home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sr / info.lha / info-sr.1989 < prev    next >
Text File  |  1993-07-24  |  93KB  |  3,033 lines

  1. From wagnerj@iris.ucdavis.edu  Mon Jun 26 00:18:51 1989
  2. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  3.     id AA01181; Mon, 26 Jun 89 00:18:51 MST
  4. Received: from iris.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.10)
  5.     id AA01126; Mon, 26 Jun 89 00:18:27 PDT
  6. Received: by iris (1.2/3.14)
  7.     id AA21073; Mon, 26 Jun 89 00:15:36 pdt
  8. Date: Mon, 26 Jun 89 00:15:36 pdt
  9. From: wagnerj@iris.ucdavis.edu (John Michael Wagner)
  10. Message-Id: <8906260715.AA21073@iris>
  11. To: info-sr@arizona.edu
  12.  
  13. I am trying to port SR to the Sun 4, working with Dr. Ron Olsson.
  14. The SPARC architecture is new to me, as is assembly.  The major
  15. routines, possibly the only routines, I need to port are, of
  16. course, the run-time support routines for sr_build_context,
  17. etc.  The Mips is also a RISC machine, but totally different; I
  18. thought it might be of help, but I don't think that will be the case.
  19. My major stumbling block is, at this time, which registers need to
  20. be saved.  Everything else is rather trivial.  Perhaps there
  21. is someone else interested in this port who knows Sun 4 assembly
  22. and, more specifically, the C/assembly interface.  Any help/
  23. suggestions/comments would be appreciated.  E-mail me at
  24. wagnerj@iris.ucdavis.edu
  25. Thanks in advance for any/all replies!
  26. -John Wagner
  27.  
  28.  
  29. From gmt  Thu Jul 27 10:24:41 1989
  30. Date: Thu, 27 Jul 89 10:24:41 MST
  31. From: "Gregg Townsend" <gmt>
  32. Message-Id: <8907271724.AA06369@megaron.arizona.edu>
  33. Received: by megaron.arizona.edu (5.59-1.7/15)
  34.     id AA06369; Thu, 27 Jul 89 10:24:41 MST
  35. To: info-sr
  36. Subject: announcing SR version 1.1
  37.  
  38. A revised implementation of the SR programming language is now available from
  39. the University of Arizona by anonymous FTP or by mail.  The new version is a
  40. little faster, a little more robust, and a lot more portable.  Some minor
  41. changes and enhancements have also been made to the language itself.
  42. [I'll post the release notes as a separate message.]
  43.  
  44. SR (Synchronizing Resources) is designed for writing distributed programs.
  45. The main language constructs are resources and operations.  Resources
  46. encapsulate processes and variables they share; operations provide the primary
  47. mechanism for process interaction.  SR provides a novel integration of the
  48. mechanisms for invoking and servicing operations.  Consequently, all of local
  49. and remote procedure call, rendezvous, message passing, dynamic process
  50. creation, multicast, and semaphores are supported.  An overview of the
  51. language and implementation appeared in the January, 1988, issue of TOPLAS
  52. (ACM Transactions on Programming Languages and Systems 10,1, 51-86).
  53.  
  54. SR has been used at a number of universities and labs for course work
  55. and research projects involving concurrent programming.  It has been
  56. used in concurrent programming courses to reinforce concepts with
  57. small programming projects and with larger projects such as replicated
  58. databases, distributed simulations, and parts of distributed operating
  59. systems such as file systems and command interpreters.  SR has also
  60. been used as a tool in several masters theses and to implement larger
  61. systems such as a system for mixed language programming, one for
  62. distributed implementation of graph algorithms, experiments with load
  63. balancing algorithms, and experiments with upcall program structures.
  64.  
  65. SR now runs on any of these machines:
  66.     Vax  (BSD Unix, or Ultrix with gcc)
  67.     Sun 2, Sun 3, or Sun 4
  68.     Decstation 3100
  69.     NeXT
  70.     Hewlett Packard 9000 (series 300 and 800)
  71.     Encore Multimax  (Umax)
  72. An SR program runs on one or more networked machines of the same architecture.
  73.  
  74. SR is available by anonymous FTP from Arizona.EDU (128.196.128.118 or
  75. 192.12.69.1).  SR tar(1) files are available in the sr subdirectory;
  76. be sure to transfer files in binary (image) mode.  The files are:
  77.  
  78.     sr.tar    The SR programming language, including source code,
  79.         documentation, checkout programs, and examples.
  80.  
  81.     vs.tar    Extended verification suite, needed only if you're going to
  82.         modify the system or port it to a new architecture.
  83.  
  84. The same files are also available in compress(1) form as sr.tar.Z and vs.tar.Z. 
  85. If you pick up a copy of SR by FTP, please let us know by email to
  86. "sr-project@Arizona.EDU".  This address can also be used for any questions or
  87. comments.  Via uucp, you can reach us at uunet!arizona!sr-project.
  88.  
  89. SR is available by mail on 1/2" magnetic tape or 1/4" Sun cartridge.  For
  90. details and an order blank, contact the SR project at the email address above;
  91. or call (602) 621-2018; or send a letter to:
  92.  
  93.     SR Project
  94.     Department of Computer Science
  95.     University of Arizona
  96.     Tucson, AZ  85721
  97.  
  98. An electronic mailing list is in place for discussing SR topics.  You can
  99. join by sending your email address to "info-sr-request@Arizona.EDU".
  100.  
  101. From gmt  Thu Jul 27 10:28:47 1989
  102. Date: Thu, 27 Jul 89 10:28:47 MST
  103. From: "Gregg Townsend" <gmt>
  104. Message-Id: <8907271728.AA06740@megaron.arizona.edu>
  105. Received: by megaron.arizona.edu (5.59-1.7/15)
  106.     id AA06740; Thu, 27 Jul 89 10:28:47 MST
  107. To: info-sr
  108. Subject: SR 1.1 release notes
  109.  
  110.  
  111.  
  112.               Release Notes for SR Version 1.1
  113.  
  114.  
  115.                        Gregg Townsend
  116.  
  117.                Department of Computer Science
  118.                  The University of Arizona
  119.  
  120.                        July 24, 1989
  121.  
  122.  
  123.      This document surveys the  changes  introduced  between
  124. Version  1.0 and Version 1.1 of the SR Programming Language.
  125. The revised language is  described  more  precisely  in  the
  126. reference manual.
  127.  
  128.  
  129. New Platforms
  130.  
  131.      SR now supports a wider  variety  of  system  architec-
  132. tures.   New systems include the Decstation 3100, the Sun 4,
  133. the NeXT  computer  system,  and  the  Hewlett-Packard  9000
  134. (series  300  and  800).   SR can now also run on Vax Ultrix
  135. systems if the GNU C compiler is available.  As a result  of
  136. the  modifications  these systems required, additional ports
  137. should be considerably easier.
  138.  
  139.  
  140. Incompatible Language Changes
  141.  
  142.      Signatures.  Scalars are no longer considered  compati-
  143. ble with arrays, even if the size is the same.  For example,
  144. an integer vector of length 1 is no  longer  interchangeable
  145. with  a  simple  integer.   The new restriction is partially
  146. enforced at this time and we anticipate stricter checking in
  147. the future.
  148.  
  149.      Character Literals.   Single  quotes  now  designate  a
  150. character  literal  instead  of  a  string  literal.  Double
  151. quotes still define a string literal.  A  character  literal
  152. has type char and contains only one character.  For example,
  153. 'x' and '\n' are character literals, while "x\n" is still  a
  154. string literal.
  155.  
  156.      String literals must be replaced by character  literals
  157. in  certain  situations.  A string can no longer be assigned
  158. to a simple char variable nor passed as an argument  to  the
  159. char() conversion function, so
  160.         var c    : char := "X"
  161.         var z[3] : char := ([3] char("z"))
  162.  
  163. become
  164.         var c    : char := 'X'
  165.         var z[3] : char := ([3] 'z')
  166.  
  167.  
  168. Language Extensions
  169.  
  170.      Operation Declarations.   For  consistency  with  other
  171. declarations, the syntax for operation declarations has been
  172. extended.  The forms op a, b, c: optypename and  op  x(...),
  173. y(...), z(...) are now accepted.
  174.  
  175.      Semaphores.  A new sem keyword allows explicit declara-
  176. tion  of  semaphores.   New P(name) and V(name) builtins are
  177. also provided.  These abbreviations provide no  new  facili-
  178. ties  but  sometimes  allow  a  clearer  expression  of  the
  179. programmer's intentions.  Diagnostics are still in terms  of
  180. the underlying implementation as special operations.
  181.  
  182.      Processes.  SR now allows the specification of quantif-
  183. iers  when  declaring processes, for example process p (i:=1
  184. to 3) declares an array of processes.
  185.  
  186.      Co Statements.  A send statement is now allowed as  the
  187. invocation part of a co statement.
  188.  
  189.      Input Statements.  An else clause is now  allowed,  and
  190. will  be executed if no invocation is selectable.  st is now
  191. allowed as an alternative to and for introducing a synchron-
  192. ization expression.
  193.  
  194.      Pointers.  Pointer arithmetic, similar to  that  of  C,
  195. has been added.  Pointers can now be printed using write and
  196. writes.  A generic pointer type ptr any has been added.
  197.  
  198.      New Timing Functions.  age() returns the  elapsed  time
  199. since  creation  of  the current virtual machine.  nap(msec)
  200. suspends the current SR process for a specified interval.
  201.  
  202.  
  203. Commands and Tools
  204.  
  205.      srl now accepts .a files as command arguments to  allow
  206. linking with user libraries of C functions.
  207.  
  208.      srl no longer creates a re-srl file.  The  re-srl  file
  209. caused more confusion than it was worth.
  210.  
  211.      srm has a new -s option to produce a smarter Makefile.
  212.  
  213.      srgrind is a new script that uses vgrind to  format  SR
  214. code for troff.
  215.  
  216.      An SR editing mode for GNU Emacs is now provided.
  217.  
  218.  
  219. Internal Improvements
  220.  
  221.      Numerous bugs, notably some involving virtual machines,
  222. have been fixed.
  223.  
  224.      I/O waiting is handled  much  more  intelligently,  and
  225. periodic  timer  interrupts are no longer used.  Among other
  226. things, these changes improve the performance  of  multiple-
  227. virtual-machine programs.
  228.  
  229.      Code has been added to prevent a process in a CPU  loop
  230. from shutting out all others.
  231.  
  232.      Smarter code generation has improved the performance of
  233. in statements.
  234.  
  235.  
  236. Documentation and Examples
  237.  
  238.      The updated reference manual, Report on the SR Program-
  239. ming  Language,  Version 1.1, is included.  The installation
  240. guide and other documents were also  revised.   The  porting
  241. guide was completely rewritten.
  242.  
  243.      PostScript  versions  of  the  documentation  are   now
  244. included in the distribution.
  245.  
  246.      Some new programs have been added in the examples  sub-
  247. directory.   One of these is a working version of the ``Din-
  248. ing Philosophers'' program from the SR Overview.
  249.  
  250.  
  251. Acknowledgements
  252.  
  253.      Many of these changes are due the  efforts  of  outside
  254. contributors.   In  particular,  we thank Ron Olsson, Carole
  255. McNamee, John Wagner, and Greg Whitehead at  the  University
  256. of  California  at  Davis;  and David Jacobson, Ulrike Glav-
  257. itsch, Luigi Semenzato, and Joe Park at Hewlett-Packard.
  258.  
  259. From aprakash@dost.eecs.umich.edu  Wed Aug 16 12:18:01 1989
  260. Received: from dost.eecs.umich.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  261.     id AA10381; Wed, 16 Aug 89 12:18:01 MST
  262. Received: by dost.eecs.umich.edu (5.57/umich-5.5)
  263.     id AA02462; Wed, 16 Aug 89 15:07:23 EDT
  264. Date: Wed, 16 Aug 89 15:07:23 EDT
  265. From: aprakash@dost.eecs.umich.edu (Atul Prakash)
  266. Message-Id: <8908161907.AA02462@dost.eecs.umich.edu>
  267. To: info-sr@arizona.edu
  268. Subject: Unexpected deadlock in dining philosopher code?
  269. Cc: aprakash@dost.eecs.umich.edu
  270.  
  271.  
  272. I was running the dining philosopher solution in examples/dining directory
  273. with a slight modification on my DEC 3100 and it seems to run into 
  274. an unexpected deadlock. The only modification is to run the 
  275. program on multiple virtual machines, with each virtual machine 
  276. running one philosopher and one
  277. servant. On completing the specified number of iterations, the philosophers
  278. are supposed to print out a message "philosopher id wishes to end". On
  279. most runs, this message is successfully printed out by each philosopher. 
  280. However, at times,
  281. it is not and I have no explanation. As far as I can make out, the program
  282. is not supposed to deadlock. I am a new user of SR and I want
  283. to find out where the bug is -- in SR, in Ultrix, or in the program. Any 
  284. explanations for this behavior?
  285.  
  286. -- Atul Prakash
  287. (aprakash@zip.eecs.umich.edu)
  288.  
  289. Here is the CODE I used followed by a SCRIPT of one of the sample runs:
  290.  
  291. --------- modified code for dining.sr -----------------------
  292.  
  293.  
  294. ##  Distributed Dining Philosophers
  295. #   %W% %G%
  296. #
  297. #   Based on the example in "An Overview of the SR Language and Implementation",
  298. #   by Greg Andrews, Ron Olsson, and a cast of thousands, in the January, 1988
  299. #   issue of TOPLAS (ACM Transactions on Programming Languages and Systems 10,1,
  300. #   51-86).
  301. #
  302. #   The algorithm is from Chandy and Misra's "Drinking Philosophers Problem",
  303. #   which appeared in the October, 1984, issue of TOPLAS (6,4, 632-646).
  304. #
  305. #   usage:  a.out n s    (for n philosophers and s sessions)
  306.  
  307.  
  308.  
  309. #   Abstract operations define two types of servant operations.
  310.  
  311. resource PhilOps        # services provided to the philosopher
  312.     op getforks()  {call}
  313.     op relforks()
  314. end
  315.  
  316.  
  317. resource ServOps        # messages exchanged among servants
  318.     op needL()    {send}        # requests for a fork
  319.     op needR()    {send}
  320.     op passL()    {send}        # passing a fork to a neighbor
  321.     op passR()    {send}
  322. end
  323.  
  324.  
  325.  
  326. #   Servants do all the work.  There's one for each philosopher.
  327.  
  328. resource Servant
  329.     extend PhilOps, ServOps
  330.     op links(l,r : cap ServOps)            # init neighbor links
  331.     op forks(haveL, dirtyL, haveR, dirtyR : bool)    # init fork values
  332.  
  333. body Servant(id : int)
  334.     var l, r : cap ServOps
  335.     var haveL, dirtyL, haveR, dirtyR : bool
  336.     op hungry()    {send}
  337.     op eat()    {send}
  338.  
  339.     proc getforks()
  340.     write("philosopher", id, "is hungry")
  341.     send hungry()     # let server know philosopher is hungry
  342.     receive eat()     # wait for permission to eat
  343.     end
  344.  
  345.  
  346.  
  347.     process server
  348.     receive links(l,r)
  349.     receive forks(haveL,dirtyL,haveR,dirtyR)
  350.     write("servant",id,"is executing")
  351.         do true->
  352.         in hungry() ->
  353.         # ask for forks I do not have -- note: I ask my right
  354.         # neighbor for his left fork, and my left neighbor for
  355.         # his right fork
  356.             if ~haveR -> send r.needL() fi
  357.             if ~haveL -> send l.needR() fi
  358.         # wait until I have both forks
  359.             do ~(haveL & haveR) ->
  360.             in passL() -> haveL := true; dirtyL := false
  361.             [] passR() -> haveR := true; dirtyR := false
  362.             [] needR() & dirtyR ->
  363.                 haveR := false; dirtyR := false
  364.                 send r.passL()
  365.             [] needL() & dirtyL ->
  366.                 haveL := false; dirtyL := false
  367.                 send l.passR()
  368.             ni
  369.             od
  370.         # let my philosopher eat; wait for him to finish
  371.             send eat(); dirtyL := true; dirtyR := true
  372.             receive relforks()
  373.         [] needR() ->   
  374.         # right neighbor needs his left fork, which is my right fork
  375.             haveR := false; dirtyR := false
  376.             send r.passL()
  377.         [] needL() ->
  378.         # left neighbor needs his right fork, which is my left fork
  379.             haveL := false; dirtyL := false
  380.             send l.passR()
  381.  
  382.         ni
  383.     od
  384.     end server
  385.  
  386. end Servant
  387.  
  388.  
  389.  
  390. #  The Philosopher resource is simple.
  391.  
  392. resource Philosopher
  393.     import PhilOps
  394.  
  395. body Philosopher(myservant : cap PhilOps; id, t : int)
  396.  
  397.     process phil
  398.     write("philosopher", id, "is beginning")
  399.     fa i := 1 to t ->
  400.         myservant.getforks()
  401.         write("philosopher",id,"is eating")        # eat
  402.         myservant.relforks()
  403.         write("philosopher",id,"is thinking")    # think
  404.     af
  405.     write("philosopher", id, "wishes to end")
  406.     end
  407.  
  408. end Philosopher
  409.  
  410.  
  411.  
  412.  
  413. #  The main resource starts everything up.
  414.  
  415. resource Main
  416.     import Philosopher, PhilOps, ServOps, Servant
  417.  
  418. body Main()
  419.     initial
  420.     var n := 5
  421.     var t := 3
  422.     getarg(1,n)    # get number of philosophers, if specified
  423.     getarg(2,t)    # get session count, if specified
  424.     
  425.       var s[1:n]  : cap Servant
  426.       var si[1:n] : cap ServOps
  427.     var pi[1:n] : cap PhilOps
  428.     var p[1:n]  : cap Philosopher
  429.     var vmcap[1:n] : cap vm
  430.  
  431.     # create five virtual machines, one for each servant and
  432.     #  philosopher pair.
  433.       fa i := 1 to n ->
  434.         vmcap[i] := create vm() on 0
  435.       af
  436.  
  437.     # create each servant and philosopher
  438.         fa i := 1 to n ->
  439.         s[i] := create Servant(i) on vmcap[1]
  440.         si[i].needL := s[i].needL        # build ServantOp cap
  441.         si[i].needR := s[i].needR
  442.         si[i].passL := s[i].passL
  443.         si[i].passR := s[i].passR
  444.  
  445.         pi[i].getforks := s[i].getforks    # build PhilosopherOp cap
  446.         pi[i].relforks := s[i].relforks
  447.         p[i] := create Philosopher(pi[i],i,t) on vmcap[1]
  448.       af
  449.     # give each Servant its links to neighboring Servants
  450.       send s[1].links(si[n],si[2])
  451.           fa i := 2 to n-1 -> send s[i].links(si[i-1],si[i+1]) af
  452.       send s[n].links(si[n-1],si[1])
  453.     # initialize each Servant's forks
  454.     #   note:  this must be asymmetric or deadlock could result
  455.     send s[1].forks(true,false,true,false)
  456.     fa i := 2 to n-1 ->  send s[i].forks(false,false,true,false) af
  457.     send s[n].forks(false,false,false,false)
  458.     end
  459.  
  460. end Main
  461.  
  462. ------------------------ A script that ends in a deadlock -------------
  463.  
  464.  
  465. % dining
  466. philosopher 1 is beginning
  467. philosopher 1 is hungry
  468. philosopher 2 is beginning
  469. philosopher 2 is hungry
  470. philosopher 3 is beginning
  471. philosopher 3 is hungry
  472. philosopher 4 is beginning
  473. philosopher 4 is hungry
  474. philosopher 5 is beginning
  475. philosopher 5 is hungry
  476. servant 1 is executing
  477. philosopher 1 is eating
  478. servant 2 is executing
  479. servant 3 is executing
  480. philosopher 1 is thinking
  481. philosopher 2 is eating
  482. philosopher 1 is hungry
  483. servant 4 is executing
  484. philosopher 2 is thinking
  485. philosopher 3 is eating
  486. servant 5 is executing
  487. philosopher 2 is hungry
  488. philosopher 3 is thinking
  489. philosopher 4 is eating
  490. philosopher 3 is hungry
  491. philosopher 4 is thinking
  492. philosopher 5 is eating
  493. philosopher 4 is hungry
  494. philosopher 5 is thinking
  495. philosopher 5 is hungry
  496.  
  497. ---- All the processes hang at this point ------
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504. From olsson@ivy.ucdavis.edu  Wed Aug 16 17:28:06 1989
  505. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  506.     id AA24595; Wed, 16 Aug 89 17:28:06 MST
  507. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  508.     id AA00566; Wed, 16 Aug 89 17:24:29 PDT
  509. Received: by ivy.ucdavis.edu (3.2/3.14)
  510.     id AA11648; Wed, 16 Aug 89 16:35:07 PDT
  511. Date: Wed, 16 Aug 89 16:35:07 PDT
  512. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  513. Message-Id: <8908162335.AA11648@ivy.ucdavis.edu>
  514. To: aprakash@dost.eecs.umich.edu, info-sr@arizona.edu
  515. In-Reply-To: Atul Prakash's message of Wed, 16 Aug 89 15:07:23 EDT <8908161907.AA02462@dost.eecs.umich.edu>
  516. Subject: Unexpected deadlock in dining philosopher code?
  517.  
  518.    Date: Wed, 16 Aug 89 15:07:23 EDT
  519.    From: aprakash@dost.eecs.umich.edu (Atul Prakash)
  520.  
  521.    I was running the dining philosopher solution in examples/dining
  522.    directory with a slight modification on my DEC 3100 and it seems to
  523.    run into an unexpected deadlock. The only modification is to run
  524.    the program on multiple virtual machines, with each virtual machine
  525.    running one philosopher and one servant. On completing the
  526.    specified number of iterations, the philosophers are supposed to
  527.    print out a message "philosopher id wishes to end". On most runs,
  528.    this message is successfully printed out by each philosopher.
  529.    However, at times, it is not and I have no explanation. As far as I
  530.    can make out, the program is not supposed to deadlock. I am a new
  531.    user of SR and I want to find out where the bug is -- in SR, in
  532.    Ultrix, or in the program. Any explanations for this behavior?
  533.  
  534. The problem is that the implementation of SR does not detect
  535. deadlock/termination in multiple vm programs.  Specifically, each
  536. server on the different vm's blocks on its input statement; if our
  537. implementation were smart, it would detect that the program is
  538. quiescent and shut everything down.
  539.  
  540. The reason you get different output from different executions is that
  541. some output is not being flushed.  If you add a `flush(stdout)'
  542. statement to the philosopher code right before its end, you'll get the
  543. same output every time.
  544.  
  545. One way to modify the program so it halts is for each philosopher to
  546. notify the main resource when it has finished; the main resource can
  547. then execute a stop statement to terminate everything.  I've attached
  548. the modified program below.  Let us know whether it works for you.
  549. BTW, distributed deadlock/termination detection is on our Wishlist,
  550. although it probably won't be implemented for at least 6 months.
  551.  
  552. (Thanks to Greg Andrews for recognizing the cause of this problem;
  553. I'm answering since his machine is down.)
  554.  
  555. ##  Distributed Dining Philosophers
  556. #   %W% %G%
  557. #
  558. #   Based on the example in "An Overview of the SR Language and Implementation",
  559. #   by Greg Andrews, Ron Olsson, and a cast of thousands, in the January, 1988
  560. #   issue of TOPLAS (ACM Transactions on Programming Languages and Systems 10,1,
  561. #   51-86).
  562. #
  563. #   The algorithm is from Chandy and Misra's "Drinking Philosophers Problem",
  564. #   which appeared in the October, 1984, issue of TOPLAS (6,4, 632-646).
  565. #
  566. #   usage:  a.out n s    (for n philosophers and s sessions)
  567.  
  568.  
  569.  
  570. #   Abstract operations define two types of servant operations.
  571.  
  572. resource PhilOps        # services provided to the philosopher
  573.     op getforks()  {call}
  574.     op relforks()
  575. end
  576.  
  577.  
  578. resource ServOps        # messages exchanged among servants
  579.     op needL()    {send}        # requests for a fork
  580.     op needR()    {send}
  581.     op passL()    {send}        # passing a fork to a neighbor
  582.     op passR()    {send}
  583. end
  584.  
  585.  
  586.  
  587. #   Servants do all the work.  There's one for each philosopher.
  588.  
  589. resource Servant
  590.     extend PhilOps, ServOps
  591.     op links(l,r : cap ServOps)            # init neighbor links
  592.     op forks(haveL, dirtyL, haveR, dirtyR : bool)    # init fork values
  593.  
  594. body Servant(id : int)
  595.     var l, r : cap ServOps
  596.     var haveL, dirtyL, haveR, dirtyR : bool
  597.     op hungry()    {send}
  598.     op eat()    {send}
  599.  
  600.     proc getforks()
  601.     write("philosopher", id, "is hungry")
  602.     send hungry()     # let server know philosopher is hungry
  603.     receive eat()     # wait for permission to eat
  604.     end
  605.  
  606.  
  607.  
  608.     process server
  609.     receive links(l,r)
  610.     receive forks(haveL,dirtyL,haveR,dirtyR)
  611.     write("servant",id,"is executing")
  612.         do true->
  613.         in hungry() ->
  614.         # ask for forks I do not have -- note: I ask my right
  615.         # neighbor for his left fork, and my left neighbor for
  616.         # his right fork
  617.             if ~haveR -> send r.needL() fi
  618.             if ~haveL -> send l.needR() fi
  619.         # wait until I have both forks
  620.             do ~(haveL & haveR) ->
  621.             in passL() -> haveL := true; dirtyL := false
  622.             [] passR() -> haveR := true; dirtyR := false
  623.             [] needR() & dirtyR ->
  624.                 haveR := false; dirtyR := false
  625.                 send r.passL()
  626.             [] needL() & dirtyL ->
  627.                 haveL := false; dirtyL := false
  628.                 send l.passR()
  629.             ni
  630.             od
  631.         # let my philosopher eat; wait for him to finish
  632.             send eat(); dirtyL := true; dirtyR := true
  633.             receive relforks()
  634.         [] needR() ->   
  635.         # right neighbor needs his left fork, which is my right fork
  636.             haveR := false; dirtyR := false
  637.             send r.passL()
  638.         [] needL() ->
  639.         # left neighbor needs his right fork, which is my left fork
  640.             haveL := false; dirtyL := false
  641.             send l.passR()
  642.  
  643.         ni
  644.     od
  645.     end server
  646.  
  647. end Servant
  648.  
  649.  
  650.  
  651. #  The Philosopher resource is simple.
  652.  
  653. resource Philosopher
  654.     import PhilOps
  655.  
  656. body Philosopher(myservant : cap PhilOps; id, t : int; done: cap())
  657.  
  658.     process phil
  659.     write("philosopher", id, "is beginning")
  660.     fa i := 1 to t ->
  661.         myservant.getforks()
  662.         write("philosopher",id,"is eating")        # eat
  663.         myservant.relforks()
  664.         write("philosopher",id,"is thinking")    # think
  665.     af
  666.     write("philosopher", id, "wishes to end")
  667.     send done()
  668.     end
  669.  
  670. end Philosopher
  671.  
  672.  
  673.  
  674.  
  675. #  The main resource starts everything up.
  676.  
  677. resource Main
  678.     import Philosopher, PhilOps, ServOps, Servant
  679.  
  680. body Main()
  681.     initial
  682.     var n := 5
  683.     var t := 3
  684.     getarg(1,n)    # get number of philosophers, if specified
  685.     getarg(2,t)    # get session count, if specified
  686.     
  687.       var s[1:n]  : cap Servant
  688.       var si[1:n] : cap ServOps
  689.     var pi[1:n] : cap PhilOps
  690.     var p[1:n]  : cap Philosopher
  691.     var vmcap[1:n] : cap vm
  692.     op done()
  693.  
  694.     # create five virtual machines, one for each servant and
  695.     #  philosopher pair.
  696.       fa i := 1 to n ->
  697.         vmcap[i] := create vm() on 0
  698.       af
  699.  
  700.     # create each servant and philosopher
  701.         fa i := 1 to n ->
  702.         s[i] := create Servant(i) on vmcap[1]
  703.         si[i].needL := s[i].needL        # build ServantOp cap
  704.         si[i].needR := s[i].needR
  705.         si[i].passL := s[i].passL
  706.         si[i].passR := s[i].passR
  707.  
  708.         pi[i].getforks := s[i].getforks    # build PhilosopherOp cap
  709.         pi[i].relforks := s[i].relforks
  710.         p[i] := create Philosopher(pi[i],i,t,done) on vmcap[1]
  711.       af
  712.     # give each Servant its links to neighboring Servants
  713.       send s[1].links(si[n],si[2])
  714.           fa i := 2 to n-1 -> send s[i].links(si[i-1],si[i+1]) af
  715.       send s[n].links(si[n-1],si[1])
  716.     # initialize each Servant's forks
  717.     #   note:  this must be asymmetric or deadlock could result
  718.     send s[1].forks(true,false,true,false)
  719.     fa i := 2 to n-1 ->  send s[i].forks(false,false,true,false) af
  720.     send s[n].forks(false,false,false,false)
  721.     # wait for philosophers to finish; then stop.
  722.       fa i := 1 to n -> receive done()  af
  723.       stop
  724.     end
  725.  
  726. end Main
  727.  
  728. From aprakash@dost.eecs.umich.edu  Thu Aug 17 08:30:51 1989
  729. Received: from dost.eecs.umich.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  730.     id AA06162; Thu, 17 Aug 89 08:30:51 MST
  731. Received: by dost.eecs.umich.edu (5.57/umich-5.5)
  732.     id AA03332; Thu, 17 Aug 89 11:19:40 EDT
  733. Message-Id: <8908171519.AA03332@dost.eecs.umich.edu>
  734. To: olsson@ivy.ucdavis.edu (Ron Olsson)
  735. Cc: aprakash@zip.eecs.umich.edu, info-sr@arizona.edu
  736. Subject: Re: Unexpected deadlock in dining philosopher code? 
  737. In-Reply-To: Your message of Wed, 16 Aug 89 16:35:07 -0700.
  738.              <8908162335.AA11648@ivy.ucdavis.edu> 
  739. Date: Thu, 17 Aug 89 11:19:36 EDT
  740. From: aprakash@dost.eecs.umich.edu
  741.  
  742.  
  743. I get the "deadlock" problem even with the new code Ron Olsson sent recently 
  744. for multiple virtual machine version of dining philosophers with 
  745. termination detection.
  746.  
  747. I had also initially thought that lack of deadlock detection  may be 
  748. the problem and had tried
  749. fixing it unsuccesfully with termination detection earlier (I used a 
  750. less elegant solution though then Ron Olsson sent) but avoided 
  751. including it in my previous mail as it did not affect the problem.
  752.  
  753. You have to run the program several times in order to reproduce the
  754. deadlock. On my machine (3100 running Ultrix), it occurs on 
  755. the average of once every five executions.
  756.  
  757. Below is the script from a correct run and an erroneous run 
  758. with Ron Olsson's code.
  759. I think it blocks at pretty much the same point whether there is
  760. termination detection or not.
  761.  
  762. -- Atul Prakash
  763. (aprakash@zip.eecs.umich.edu)
  764.  
  765. -------------- script for correct execution -------------------------------
  766.  
  767. %dining
  768. philosopher 5 is hungry
  769. servant 1 is executing
  770. philosopher 1 is eating
  771. servant 2 is executing
  772. servant 3 is executing
  773. philosopher 1 is thinking
  774. philosopher 2 is eating
  775. philosopher 1 is hungry
  776. servant 4 is executing
  777. philosopher 2 is thinking
  778. philosopher 3 is eating
  779. philosopher 2 is hungry
  780. servant 5 is executing
  781. philosopher 3 is thinking
  782. philosopher 4 is eating
  783. philosopher 1 is eating
  784. philosopher 3 is hungry
  785. philosopher 4 is thinking
  786. philosopher 1 is thinking
  787. philosopher 5 is eating
  788. philosopher 2 is eating
  789. philosopher 4 is hungry
  790. philosopher 1 is hungry
  791. philosopher 5 is thinking
  792. philosopher 2 is thinking
  793. philosopher 3 is eating
  794. philosopher 5 is hungry
  795. philosopher 2 is hungry
  796. philosopher 3 is thinking
  797. philosopher 4 is eating
  798. philosopher 1 is eating
  799. philosopher 3 is hungry
  800. philosopher 4 is thinking
  801. philosopher 1 is thinking
  802. philosopher 5 is eating
  803. philosopher 2 is eating
  804. philosopher 4 is hungry
  805. philosopher 1 wishes to end
  806. philosopher 5 is thinking
  807. philosopher 2 is thinking
  808. philosopher 3 is eating
  809. philosopher 5 is hungry
  810. philosopher 2 wishes to end
  811. philosopher 3 is thinking
  812. philosopher 4 is eating
  813. philosopher 3 wishes to end
  814. philosopher 4 is thinking
  815. philosopher 5 is eating
  816. philosopher 4 wishes to end
  817. philosopher 5 is thinking
  818. philosopher 5 wishes to end
  819.  
  820. The program successfully terminates here and you get the Unix prompt.
  821.  
  822. --------- script for incorrect execution
  823. %dining
  824. philosopher 1 is beginning
  825. philosopher 1 is hungry
  826. philosopher 2 is beginning
  827. philosopher 2 is hungry
  828. philosopher 3 is beginning
  829. philosopher 3 is hungry
  830. philosopher 4 is beginning
  831. philosopher 4 is hungry
  832. philosopher 5 is beginning
  833. philosopher 5 is hungry
  834. servant 1 is executing
  835. philosopher 1 is eating
  836. servant 2 is executing
  837. servant 3 is executing
  838. philosopher 1 is thinking
  839. philosopher 2 is eating
  840. philosopher 1 is hungry
  841. servant 4 is executing
  842. philosopher 2 is thinking
  843. philosopher 3 is eating
  844. servant 5 is executing
  845. philosopher 2 is hungry
  846. philosopher 3 is thinking
  847. philosopher 4 is eating
  848. philosopher 3 is hungry
  849. philosopher 4 is thinking
  850. philosopher 5 is eating
  851. philosopher 4 is hungry
  852. philosopher 5 is thinking
  853. philosopher 5 is hungry
  854.  
  855. The program hangs here and has to be killed. Couple of things to notice
  856. here for this run.  First notice that everyone is supposed to eat three 
  857. times (the default); however, 1 has only once. So, we are not 
  858. at termination point.  Further, at this point 5 is supposed to pass 
  859. its forks to 1 or 4 and so either 1 or 4 should be able to eat. However, 
  860. that is not happening.
  861.  
  862. From jacobson%cello@hplabs.hp.com  Fri Aug 18 06:59:32 1989
  863. Received: from hplms2.hpl.hp.com by megaron.arizona.edu (5.59-1.7/15) via SMTP
  864.     id AA06562; Fri, 18 Aug 89 06:59:32 MST
  865. Received: from cello.HPL.HP.COM (cello.hpl.hp.com) by hplms2.hp.com; Fri, 18 Aug 89 06:55:57 pdt
  866. Received: by cello.HPL.HP.COM; Thu, 17 Aug 89 21:08:30 pdt
  867. Date: Thu, 17 Aug 89 21:08:30 pdt
  868. From: David Jacobson <jacobson%cello@hplabs.hp.com>
  869. Message-Id: <8908180408.AA10346@cello.HPL.HP.COM>
  870. To: info-sr@arizona.edu, jacobson%cello@hplabs.hp.com
  871. Subject: Dining philosopher problems
  872.  
  873. When I run the Ron Olssson's code for the philosophers on an HP
  874. 9000s800 (actually an 835) running HP-UX version 3.10 there are two
  875. problems.  After the first round where the philosophers begin, each
  876. philosopher just runs in isolation.  (This is running with the default
  877. 5 philosophers and 3 rounds.)  In addition, about every 5 times or
  878. so, it stops early, just terminating normally.  (It does not need to
  879. be killed as others have reported.  A script of one such run follows.
  880.  
  881. -- David Jacobson
  882.    HP Labs
  883. ------------------------
  884. philosopher 1 is beginning
  885. philosopher 1 is hungry
  886. philosopher 2 is beginning
  887. philosopher 2 is hungry
  888. philosopher 3 is beginning
  889. philosopher 3 is hungry
  890. philosopher 4 is beginning
  891. philosopher 4 is hungry
  892. philosopher 5 is beginning
  893. philosopher 5 is hungry
  894. servant 1 is executing
  895. philosopher 1 is eating
  896. philosopher 1 is thinking
  897. philosopher 1 is hungry
  898. philosopher 1 is eating
  899. philosopher 1 is thinking
  900. philosopher 1 is hungry
  901. philosopher 1 is eating
  902. philosopher 1 is thinking
  903. philosopher 1 wishes to end
  904. servant 2 is executing
  905. philosopher 2 is eating
  906. philosopher 2 is thinking
  907. philosopher 2 is hungry
  908. philosopher 2 is eating
  909. philosopher 2 is thinking
  910. philosopher 2 is hungry
  911. philosopher 2 is eating
  912. philosopher 2 is thinking
  913. philosopher 2 wishes to end
  914. servant 3 is executing
  915. philosopher 3 is eating
  916. philosopher 3 is thinking
  917. philosopher 3 is hungry
  918. philosopher 3 is eating
  919. philosopher 3 is thinking
  920. philosopher 3 is hungry
  921. philosopher 3 is eating
  922. philosopher 3 is thinking
  923. philosopher 3 wishes to end
  924. servant 4 is executing
  925.  
  926. From deng@chaos.sunysb.edu  Fri Aug 18 07:16:04 1989
  927. Received: from chaos.sunysb.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  928.     id AA07389; Fri, 18 Aug 89 07:16:04 MST
  929. Received:  by chaos.sunysb.edu (3.2/25-eef)
  930.     id AA05156; Fri, 18 Aug 89 10:04:26 EDT
  931. Date: Fri, 18 Aug 89 10:04:26 EDT
  932. From: Yuefan Deng <deng@chaos.sunysb.edu>
  933. Message-Id: <8908181404.AA05156@chaos.sunysb.edu>
  934. To: info-sr@arizona.edu, jacobson%cello@hplabs.hp.com
  935. Subject: Re:  Dining philosopher problems
  936.  
  937. Could you all change my address from deng@cmcl2.nyu.edu to
  938. deng@chaos.sunysb.edu. Thanks in advance.
  939.  
  940. y deng
  941.  
  942. From jacobson%cello@hplabs.hp.com  Fri Aug 18 09:21:31 1989
  943. Received: from hplms2.hpl.hp.com by megaron.arizona.edu (5.59-1.7/15) via SMTP
  944.     id AA14754; Fri, 18 Aug 89 09:21:31 MST
  945. Received: from cello.HPL.HP.COM (cello.hpl.hp.com) by hplms2.hp.com; Fri, 18 Aug 89 09:17:50 pdt
  946. Received: by cello.HPL.HP.COM; Fri, 18 Aug 89 09:17:31 pdt
  947. Date: Fri, 18 Aug 89 09:17:31 pdt
  948. From: David Jacobson <jacobson%cello@hplabs.hp.com>
  949. Message-Id: <8908181617.AA18157@cello.HPL.HP.COM>
  950. To: info-sr@arizona.edu
  951. Cc: jacobson%cello@hplabs.hp.com
  952. Subject: Dining philosophers
  953.  
  954. I added a little bit of code to the loop that collects the done
  955. messages to print out which philosopher was done.  Now on an
  956. HP9000s800 the philosophers proceed somewhat irregularly, instead of
  957. philosopher 1 eating all 3 times, then philosopher 2, etc.  Observe
  958. the new code at the end.  (See below for 2 more statements that were
  959. added, though.)
  960.  
  961. However, sometimes I got a deadlock in which all 5 philosopher's are
  962. hungry.  (A script follows.)  I traced the problem to a bug in the sr
  963. code for the servant.  When a philosopher is hungry, her servant is
  964. willing to yield a dirty fork to a neighboring servant.  The servant
  965. should ask for it back, though, and the code forgot to do that.  
  966.  
  967. I've added calls to needL and needR, as shown in the code at the end.
  968. (They were not there in the code that generated the log shown below.)
  969. Now things seem to work ok.  (We still have the bug mentioned in my
  970. previous message, though.)
  971.  
  972.   -- David Jacobson
  973.  
  974. ---------------------------------
  975. This log code comes from a revision of Ron Olsson's code with an added write 
  976. statement in the collector of the done messages to identify the philosopher
  977. that is done.  
  978.  
  979. philosopher 1 is beginning
  980. philosopher 1 is hungry
  981. philosopher 2 is beginning
  982. philosopher 2 is hungry
  983. philosopher 3 is beginning
  984. philosopher 3 is hungry
  985. philosopher 4 is beginning
  986. philosopher 4 is hungry
  987. philosopher 5 is beginning
  988. philosopher 5 is hungry
  989. servant 1 is executing
  990. philosopher 1 is eating
  991. servant 2 is executing
  992. servant 3 is executing
  993. philosopher 1 is thinking
  994. philosopher 2 is eating
  995. philosopher 1 is hungry
  996. servant 4 is executing
  997. philosopher 2 is thinking
  998. philosopher 3 is eating
  999. servant 5 is executing
  1000. philosopher 2 is hungry
  1001. philosopher 3 is thinking
  1002. philosopher 4 is eating
  1003. philosopher 3 is hungry
  1004. philosopher 4 is thinking
  1005. philosopher 5 is eating
  1006. philosopher 4 is hungry
  1007. philosopher 5 is thinking
  1008. philosopher 5 is hungry
  1009.  
  1010. The program hung at this point and had to be killed.
  1011. ---------------------------------------
  1012. ##  Distributed Dining Philosophers
  1013. #   %W% %G%
  1014. #
  1015. #   Based on the example in "An Overview of the SR Language and Implementation",
  1016. #   by Greg Andrews, Ron Olsson, and a cast of thousands, in the January, 1988
  1017. #   issue of TOPLAS (ACM Transactions on Programming Languages and Systems 10,1,
  1018. #   51-86).
  1019. #
  1020. #   The algorithm is from Chandy and Misra's "Drinking Philosophers Problem",
  1021. #   which appeared in the October, 1984, issue of TOPLAS (6,4, 632-646).
  1022. #
  1023. #   usage:  a.out n s    (for n philosophers and s sessions)
  1024.  
  1025.  
  1026.  
  1027. #   Abstract operations define two types of servant operations.
  1028.  
  1029. resource PhilOps        # services provided to the philosopher
  1030.     op getforks()  {call}
  1031.     op relforks()
  1032. end
  1033.  
  1034.  
  1035. resource ServOps        # messages exchanged among servants
  1036.     op needL()    {send}        # requests for a fork
  1037.     op needR()    {send}
  1038.     op passL()    {send}        # passing a fork to a neighbor
  1039.     op passR()    {send}
  1040. end
  1041.  
  1042.  
  1043.  
  1044. #   Servants do all the work.  There's one for each philosopher.
  1045.  
  1046. resource Servant
  1047.     extend PhilOps, ServOps
  1048.     op links(l,r : cap ServOps)            # init neighbor links
  1049.     op forks(haveL, dirtyL, haveR, dirtyR : bool)    # init fork values
  1050.  
  1051. body Servant(id : int)
  1052.     var l, r : cap ServOps
  1053.     var haveL, dirtyL, haveR, dirtyR : bool
  1054.     op hungry()    {send}
  1055.     op eat()    {send}
  1056.  
  1057.     proc getforks()
  1058.     write("philosopher", id, "is hungry")
  1059.     send hungry()     # let server know philosopher is hungry
  1060.     receive eat()     # wait for permission to eat
  1061.     end
  1062.  
  1063.  
  1064.  
  1065.     process server
  1066.     receive links(l,r)
  1067.     receive forks(haveL,dirtyL,haveR,dirtyR)
  1068.     write("servant",id,"is executing")
  1069.         do true->
  1070.         in hungry() ->
  1071.         # ask for forks I do not have -- note: I ask my right
  1072.         # neighbor for his left fork, and my left neighbor for
  1073.         # his right fork
  1074.             if ~haveR -> send r.needL() fi
  1075.             if ~haveL -> send l.needR() fi
  1076.         # wait until I have both forks
  1077.             do ~(haveL & haveR) ->
  1078.             in passL() -> haveL := true; dirtyL := false
  1079.             [] passR() -> haveR := true; dirtyR := false
  1080.             [] needR() & dirtyR ->
  1081.                 haveR := false; dirtyR := false
  1082.                 send r.passL()
  1083.                 send r.needL()  # ask for fork back
  1084.             [] needL() & dirtyL ->
  1085.                 haveL := false; dirtyL := false
  1086.                 send l.passR()
  1087.                 send l.needR()  # ask for fork back
  1088.             ni
  1089.             od
  1090.         # let my philosopher eat; wait for him to finish
  1091.             send eat(); dirtyL := true; dirtyR := true
  1092.             receive relforks()
  1093.         [] needR() ->   
  1094.         # right neighbor needs his left fork, which is my right fork
  1095.             haveR := false; dirtyR := false
  1096.             send r.passL()
  1097.         [] needL() ->
  1098.         # left neighbor needs his right fork, which is my left fork
  1099.             haveL := false; dirtyL := false
  1100.             send l.passR()
  1101.  
  1102.         ni
  1103.     od
  1104.     end server
  1105.  
  1106. end Servant
  1107.  
  1108.  
  1109.  
  1110. #  The Philosopher resource is simple.
  1111.  
  1112. resource Philosopher
  1113.     import PhilOps
  1114.  
  1115. body Philosopher(myservant : cap PhilOps; id, t : int; done: cap(n : int))
  1116.  
  1117.     process phil
  1118.     write("philosopher", id, "is beginning")
  1119.     fa i := 1 to t ->
  1120.         myservant.getforks()
  1121.         write("philosopher",id,"is eating")        # eat
  1122.         myservant.relforks()
  1123.         write("philosopher",id,"is thinking")    # think
  1124.     af
  1125.     write("philosopher", id, "wishes to end")
  1126.     send done(id)
  1127.     end
  1128.  
  1129. end Philosopher
  1130.  
  1131.  
  1132.  
  1133.  
  1134. #  The main resource starts everything up.
  1135.  
  1136. resource Main
  1137.     import Philosopher, PhilOps, ServOps, Servant
  1138.  
  1139. body Main()
  1140.     initial
  1141.     var n := 5
  1142.     var t := 3
  1143.     getarg(1,n)    # get number of philosophers, if specified
  1144.     getarg(2,t)    # get session count, if specified
  1145.     
  1146.       var s[1:n]  : cap Servant
  1147.       var si[1:n] : cap ServOps
  1148.     var pi[1:n] : cap PhilOps
  1149.     var p[1:n]  : cap Philosopher
  1150.     var vmcap[1:n] : cap vm
  1151.         op done(n:int)
  1152.         var j : int
  1153.  
  1154.     # create five virtual machines, one for each servant and
  1155.     #  philosopher pair.
  1156.       fa i := 1 to n ->
  1157.         vmcap[i] := create vm() on 0
  1158.       af
  1159.  
  1160.     # create each servant and philosopher
  1161.         fa i := 1 to n ->
  1162.         s[i] := create Servant(i) on vmcap[1]
  1163.         si[i].needL := s[i].needL        # build ServantOp cap
  1164.         si[i].needR := s[i].needR
  1165.         si[i].passL := s[i].passL
  1166.         si[i].passR := s[i].passR
  1167.  
  1168.         pi[i].getforks := s[i].getforks    # build PhilosopherOp cap
  1169.         pi[i].relforks := s[i].relforks
  1170.         p[i] := create Philosopher(pi[i],i,t,done) on vmcap[1]
  1171.       af
  1172.     # give each Servant its links to neighboring Servants
  1173.       send s[1].links(si[n],si[2])
  1174.           fa i := 2 to n-1 -> send s[i].links(si[i-1],si[i+1]) af
  1175.       send s[n].links(si[n-1],si[1])
  1176.     # initialize each Servant's forks
  1177.     #   note:  this must be asymmetric or deadlock could result
  1178.     send s[1].forks(true,false,true,false)
  1179.     fa i := 2 to n-1 ->  send s[i].forks(false,false,true,false) af
  1180.     send s[n].forks(false,false,false,false)
  1181.     # wait for philosophers to finish; then stop.
  1182.     fa i := 1 to n -> 
  1183.        receive done(j)  
  1184.        write("Recvd done from philosopher ",j)
  1185.     af
  1186.     stop
  1187.     end
  1188.  
  1189. end Main
  1190.  
  1191. From olsson@ivy.ucdavis.edu  Fri Aug 18 10:28:00 1989
  1192. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1193.     id AA20365; Fri, 18 Aug 89 10:28:00 MST
  1194. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  1195.     id AA12493; Fri, 18 Aug 89 10:24:00 PDT
  1196. Received: by ivy.ucdavis.edu (3.2/3.14)
  1197.     id AA16450; Fri, 18 Aug 89 10:23:24 PDT
  1198. Date: Fri, 18 Aug 89 10:23:24 PDT
  1199. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  1200. Message-Id: <8908181723.AA16450@ivy.ucdavis.edu>
  1201. To: jacobson%cello@hplabs.hp.com, info-sr@arizona.edu
  1202. In-Reply-To: David Jacobson's message of Fri, 18 Aug 89 09:17:31 pdt <8908181617.AA18157@cello.HPL.HP.COM>
  1203. Subject: Dining philosophers
  1204.  
  1205. Yes, the code in examples/dining has the bug you describe.  The
  1206. overview paper has it right, but we lost something in the translation.
  1207. Thanks for finding that.
  1208.  
  1209. From gmt  Fri Aug 18 15:14:36 1989
  1210. Date: Fri, 18 Aug 89 15:14:36 MST
  1211. From: "Gregg Townsend" <gmt>
  1212. Message-Id: <8908182214.AA08300@megaron.arizona.edu>
  1213. Received: by megaron.arizona.edu (5.59-1.7/15)
  1214.     id AA08300; Fri, 18 Aug 89 15:14:36 MST
  1215. To: info-sr
  1216. Subject: SR under Vax Ultrix 3.1
  1217.  
  1218. We have found that SR Version 1.1 builds and runs properly under Vax Ultrix
  1219. version 3.1 using the standard C compiler, cc.
  1220.  
  1221. This contrasts with Ultrix version 2, where cc couldn't handle SR, and so
  1222. the use of gcc was required.  Now, nothing special is needed.
  1223.  
  1224.     Gregg Townsend / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  1225.     +1 602 621 4325      gmt@Arizona.EDU       110 57 16 W / 32 13 45 N / +758m
  1226.  
  1227. From aprakash@dost.eecs.umich.edu  Mon Aug 21 07:43:27 1989
  1228. Received: from dost.eecs.umich.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1229.     id AA20868; Mon, 21 Aug 89 07:43:27 MST
  1230. Received: by dost.eecs.umich.edu (5.57/umich-5.5)
  1231.     id AA05035; Mon, 21 Aug 89 10:32:16 EDT
  1232. Message-Id: <8908211432.AA05035@dost.eecs.umich.edu>
  1233. To: olsson@ivy.ucdavis.edu (Ron Olsson)
  1234. Cc: jacobson%cello@hplabs.hp.com, info-sr@arizona.edu
  1235. Subject: Re: Dining philosophers 
  1236. In-Reply-To: Your message of Fri, 18 Aug 89 10:23:24 -0700.
  1237.              <8908181723.AA16450@ivy.ucdavis.edu> 
  1238. Date: Mon, 21 Aug 89 10:32:13 EDT
  1239. From: aprakash@dost.eecs.umich.edu
  1240.  
  1241. You are welcome. It will be interesting to see what the bug is. 
  1242. Incidently, that raises a larger question of how does one go about debugging 
  1243. a program in SR, based on program translation to a different language?
  1244. Debugging multiple virtual machine programs is hard with dbx even for
  1245. programs written in C, but can -g option with dbx be somehow
  1246. used (with some manual mapping of SR names to C names, etc.) in 
  1247. stepping through a single virtual machine SR program via a debugger? This
  1248. technique was used quite successfully earlier for C++ programs that 
  1249. were translated to C (before C++ debuggers became available). 
  1250.  
  1251. -- Atul
  1252. (aprakash@zip.eecs.umich.edu)
  1253.  
  1254. From jacobson%cello@hplabs.hp.com  Fri Aug 25 09:58:10 1989
  1255. Received: from hplms2.hpl.hp.com by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1256.     id AA10959; Fri, 25 Aug 89 09:58:10 MST
  1257. Received: from cello.HPL.HP.COM (cello.hpl.hp.com) by hplms2.hp.com; Fri, 25 Aug 89 08:36:20 pdt
  1258. Received: by cello.HPL.HP.COM; Fri, 25 Aug 89 08:36:16 pdt
  1259. Date: Fri, 25 Aug 89 08:36:16 pdt
  1260. From: David Jacobson <jacobson%cello@hplabs.hp.com>
  1261. Message-Id: <8908251536.AA27066@cello.HPL.HP.COM>
  1262. To: info-sr@arizona.edu
  1263. Subject: Circular importation in resource specs.
  1264.  
  1265. There are a number of times when I have two resources that need to
  1266. import each other's specs.  For example, there might be a dictionary
  1267. resource that exports operations for mapping strings to capabilities
  1268. for foo_servers.  Foo_servers export an operation that returns
  1269. capabilies for dictionaries.
  1270.  
  1271. The obvious specs are these
  1272.  
  1273. resource dictionary
  1274.    import foo_server
  1275.    op insert(key:string(*);value cap foo_server)
  1276.    op lookup(key:string(*)) returns value cap_fooserver
  1277. end
  1278.  
  1279. resource foo_server
  1280.    import dictionary
  1281.    op mumble() returns x:cap dictionary
  1282. end
  1283.  
  1284. However, SR does not like circularity of importation.  Does anyone out
  1285. there have any suggestions about how to get around this problem?
  1286.  
  1287.   -- David Jacobson
  1288.  
  1289.  
  1290. From greg  Fri Aug 25 14:29:16 1989
  1291. Received: from paloverde.arizona.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1292.     id AA27982; Fri, 25 Aug 89 14:29:16 MST
  1293. Date: Fri, 25 Aug 89 14:29:11 MST
  1294. From: "Greg Andrews" <greg>
  1295. Message-Id: <8908252129.AA05094@paloverde.arizona.edu>
  1296. Received: by paloverde.arizona.edu; Fri, 25 Aug 89 14:29:11 MST
  1297. In-Reply-To: <8908251536.AA27066@cello.HPL.HP.COM>
  1298. To: info-sr@arizona.edu, jacobson%cello@hplabs.hp.com
  1299. Subject: Re:  Circular importation in resource specs.
  1300.  
  1301.     From: David Jacobson <jacobson%cello@hplabs.hp.com>
  1302.     To: info-sr@arizona.edu
  1303.     Subject: Circular importation in resource specs.
  1304.     
  1305.     There are a number of times when I have two resources that need to
  1306.     import each other's specs.  For example, there might be a dictionary
  1307.     resource that exports operations for mapping strings to capabilities
  1308.     for foo_servers.  Foo_servers export an operation that returns
  1309.     capabilies for dictionaries.
  1310.     
  1311.     The obvious specs are these
  1312.     
  1313.     resource dictionary
  1314.        import foo_server
  1315.        op insert(key:string(*);value cap foo_server)
  1316.        op lookup(key:string(*)) returns value cap_fooserver
  1317.     end
  1318.     
  1319.     resource foo_server
  1320.        import dictionary
  1321.        op mumble() returns x:cap dictionary
  1322.     end
  1323.     
  1324.     However, SR does not like circularity of importation.  Does anyone out
  1325.     there have any suggestions about how to get around this problem?
  1326.     
  1327.       -- David Jacobson
  1328.     
  1329. Lots of students ask the same question!  There are two solutions.
  1330. If there are just a few operations that one resource needs from
  1331. the other, put optype declarations in a global that both
  1332. resources import and have caps for the appropriate optypes.
  1333. The resources then talk to each other to get the capabilities
  1334. bound to the appropriate operations.  Better yet, have a third
  1335. resource create both the dictionary and foo_server, then have
  1336. it give each the appropriate operation capabilities for the other.
  1337.  
  1338. The second approach is to use abstract resources to encapsulate
  1339. the subset of operations of dictionary and foo_server that the
  1340. other needs.  These are compiled before the concrete resources,
  1341. which can then import the abstract resources and have caps for them.
  1342. Getting caps bound to the actual operations is done as above,
  1343. typically by a third resource.  See the on-line decentralized
  1344. dining philosophers program for an example.
  1345.  
  1346. Because many people would like mutual imports, we are going to
  1347. bite the implementation bullet and allow it in Version 2.0
  1348. of SR, which we are starting to work on.  That version won't
  1349. be available for about a year, though, since we several other
  1350. language extensions in mind and are just getting started.
  1351.  
  1352. -- Greg Andrews
  1353.  
  1354. From jacobson%cello@hplabs.hp.com  Fri Aug 25 15:10:52 1989
  1355. Received: from hplms2.hpl.hp.com by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1356.     id AA01086; Fri, 25 Aug 89 15:10:52 MST
  1357. Received: from cello.HPL.HP.COM (cello.hpl.hp.com) by hplms2.hp.com; Fri, 25 Aug 89 15:07:15 pdt
  1358. Received: from localhost by cello.HPL.HP.COM; Fri, 25 Aug 89 15:07:12 pdt
  1359. To: "Greg Andrews" <greg@arizona.edu>
  1360. Cc: info-sr@arizona.edu
  1361. Subject: Re: Circular importation in resource specs. 
  1362. In-Reply-To: Your message of "Fri, 25 Aug 89 14:29:11 MST."
  1363.              <8908252129.AA05094@paloverde.arizona.edu> 
  1364. Date: Fri, 25 Aug 89 15:07:10 PDT
  1365. Message-Id: <28744.620086030@cello>
  1366. From: jacobson%cello@hplabs.hp.com
  1367.  
  1368. Thank you for your reply to my query.  But I think you answered a
  1369. slightly different question than I asked.  
  1370.  
  1371. In my example, the caps are for entire resources.  (I'm trying to use
  1372. resources as abstract data types.  So a cap is is used to name an
  1373. instance of the ADT.)  You have described how to pass capabilities for
  1374. *operations* around.  Note that the dining philosophers solutions
  1375. passes around capabilities for things like needL, needR, passL, passR,
  1376. getforks, and relforks that are operations that take no parameters and
  1377. return no results -- in particular no capabilities for resources.
  1378.  
  1379. The only solution that I can see is to have a combined common abstract
  1380. type, dict_foo, then, branching two ways, extend and implement it.
  1381.  
  1382. resource dict_foo
  1383.    # dictionary ops
  1384.    op insert(key:string(*);value cap dict_foo)
  1385.    op lookup(key:string(*)) returns value cap dict_foo
  1386.    # foo_server ops
  1387.    op mumble () returns x cap dict_foo
  1388. end
  1389.  
  1390. resource dictionary
  1391.    extend dict_foo
  1392. body dictionary()
  1393.    # instance data
  1394.    proc insert ...
  1395.    proc lookup ...
  1396.    proc mumble()
  1397.       write(stderr,"This is really a dictionary, you shouldn't call mumble")
  1398.       stop
  1399.    end
  1400. end
  1401.  
  1402. # and similarly for foo_server
  1403.  
  1404.   -- David Jacobson
  1405.  
  1406. From greg  Fri Aug 25 15:41:13 1989
  1407. Received: from paloverde.arizona.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1408.     id AA02874; Fri, 25 Aug 89 15:41:13 MST
  1409. Date: Fri, 25 Aug 89 15:41:06 MST
  1410. From: "Greg Andrews" <greg>
  1411. Message-Id: <8908252241.AA05330@paloverde.arizona.edu>
  1412. Received: by paloverde.arizona.edu; Fri, 25 Aug 89 15:41:06 MST
  1413. In-Reply-To: <28744.620086030@cello>
  1414. To: greg@arizona.edu, jacobson%cello@hplabs.hp.com
  1415. Subject: Re: Circular importation in resource specs.
  1416. Cc: info-sr@arizona.edu
  1417.  
  1418. David is correct in his comments and shows how to
  1419. program around the lack of mutual imports.  As I
  1420. said earlier, we will eventually support mutual import
  1421. to simplify the kind of mutual resource interaction
  1422. David described.
  1423.  
  1424. From csc319@computing.lancaster.ac.uk  Mon Oct  9 12:27:15 1989
  1425. Received: from rvax.ccit.arizona.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1426.     id AA11528; Mon, 9 Oct 89 12:27:15 MST
  1427. Received: from UKACRL.BITNET by rvax.ccit.arizona.edu; Mon, 9 Oct 89 11:59 MST
  1428. Received: from RL.IB by UKACRL.BITNET (Mailer X1.25) with BSMTP id 5243; Mon,
  1429.  09 Oct 89 16:37:07 BST
  1430. Date: Mon, 9 Oct 89 15:37:59 GMT
  1431. From: csc319@computing.lancaster.ac.uk
  1432. Subject: Change of Address
  1433. To: info-sr@arizona.edu
  1434. Via:        UK.AC.LANCS.COMP;  9 OCT 89 16:37:02 BST
  1435. Message-Id: <9299.8910091537@dcl-ugrad.comp.lancs.ac.uk>
  1436.  
  1437. Please could you change my mail address from:
  1438.  
  1439.         csc220@comp.lancs.ac.uk.
  1440.  
  1441. to:
  1442.  
  1443.         csc319@comp.lancs.ac.uk.
  1444.  
  1445.  
  1446.         Thanks
  1447.             Graham (Dean)
  1448.  
  1449. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Wed Oct 11 18:55:22 1989
  1450. Received: from ucbvax.Berkeley.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1451.     id AA08298; Wed, 11 Oct 89 18:55:22 MST
  1452. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.37)
  1453.     id AA02634; Wed, 11 Oct 89 18:55:12 -0700
  1454. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  1455.     id AA11305; Wed, 11 Oct 89 18:56:50 PDT
  1456. Message-Id: <8910120156.AA11305@awesome.berkeley.edu>
  1457. To: info-sr@arizona.edu
  1458. Subject: novice question
  1459. Date: Wed, 11 Oct 89 18:56:48 -0700
  1460. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  1461.  
  1462.  
  1463.    I just installed SR on our SUNs and the first program I've tried,
  1464.    aside from existing examples, has me quite befuddled.
  1465.  
  1466.    What I want to do is create a "master" on the local SUN, and start
  1467.    a "slave" on each SUN named on the command line.  The "slaves" do
  1468.    some trivial computation and then report to the "master" that
  1469.    they are done.  The "master" waits for everyone to report back and
  1470.    then stops.
  1471.  
  1472.    The file "remote.sr" is at the end of this message.  Here is what
  1473.    happens.
  1474.  
  1475.  
  1476.    % srm
  1477.    % make
  1478.    sr -c remote.sr
  1479.    srl -o a.out master slave main
  1480.    % a.out awesome totally
  1481.    Slaves will be on:
  1482.    awesome
  1483.    totally
  1484.    makeslaves active
  1485.    makemaster active
  1486.  
  1487.    I am the master  2  slaves!
  1488.    waiting ...
  1489.    RTS warning: 3 blocked process during termination
  1490.    %
  1491.  
  1492.  
  1493.    It would appear that none of the sends or receives succeed.
  1494.    Any suggestions?
  1495.  
  1496. thanks,
  1497.  David Jones
  1498.  djones@awesome.berkeley.edu
  1499.  
  1500.  
  1501.  
  1502. ----------- cut here ------------------
  1503.  
  1504. resource master
  1505.    op handshake(id:int)
  1506. body master(n:int)
  1507.    initial
  1508.       var  num            :int
  1509.  
  1510.       write("I am the master of ",n," slaves!")
  1511.       fa i:=1 to n ->
  1512.      write("waiting ...")
  1513.      flush(stdout)
  1514.      receive handshake(num)
  1515.      write("slave ",num," is done")
  1516.       af
  1517.       write("everyone is done.")
  1518.       flush(stdout)
  1519.       stop
  1520.    end
  1521. end master
  1522.  
  1523.  
  1524. resource slave
  1525.    import master
  1526.    op number() returns n:int
  1527. body slave(m:cap master)
  1528.    external gethostname(res s:string(*); namelen:int)
  1529.  
  1530.    var  h        :string(64)
  1531.    var  myid        :int
  1532.  
  1533.    initial
  1534.       gethostname(h,maxlength(h))
  1535.       myid:=mymachine()
  1536.    end
  1537.  
  1538.    process v
  1539.       writes("Slave on host ",h," running.\n")
  1540.       flush(stdout)
  1541.       nap(1000)
  1542.       write("Slave on host ",h," done.\n")
  1543.       flush(stdout)
  1544.       send m.handshake(myid)
  1545.    end
  1546.  
  1547.    proc number() returns n
  1548.       n:=myid
  1549.       write("slave.number(",n,")")
  1550.       flush(stdout)
  1551.    end number
  1552. end slave
  1553.  
  1554.  
  1555. resource main
  1556.    import master
  1557.    import slave
  1558.    op who_is_master(m:cap master) {send}
  1559. body main()
  1560.    var  n            :int
  1561.  
  1562.    initial
  1563.       var s            :string(100)
  1564.  
  1565.       n:=numargs()
  1566.       write("Slaves will be on: ")
  1567.       fa i:=1 to n ->
  1568.      getarg(i,s)
  1569.      write(s)
  1570.       af
  1571.       flush(stdout)
  1572.    end
  1573.  
  1574.    process makeslaves
  1575.       var s            :string(100)
  1576.       var remote        :cap vm
  1577.       var mastercap        :cap master
  1578.       var slavecap[1:n]        :cap slave
  1579.  
  1580.       write("makeslaves active")
  1581.       flush(stdout)
  1582.       receive who_is_master(mastercap)
  1583.       write("about to create slaves\n")
  1584.       flush(stdout)
  1585.       fa i := 1 to n ->
  1586.      getarg(i,s)
  1587.      locate(i,s)
  1588.      remote:=create vm() on i
  1589.      if (remote = null) ->
  1590.         write(stderr,"can't create vm on",s,"\n")
  1591.         flush(stderr)
  1592.      [] else ->
  1593.         write("creating slave on ",s,"\n")
  1594.         flush(stdout)
  1595.         slavecap[i]:=create slave(mastercap) on remote
  1596.         if (slavecap[i] = null) ->
  1597.            write("create slave on host ",s,", machine ",i," failed.\n")
  1598.            flush(stdout)
  1599.         [] else ->
  1600.            write("slave ",i," has machine id ",slavecap[i].number())
  1601.            flush(stdout)
  1602.         fi
  1603.      fi
  1604.       af
  1605.       write("all slaves created")
  1606.       flush(stdout)
  1607.       nap(30000)
  1608.    end makeslaves
  1609.  
  1610.    process makemaster
  1611.       var  mastercap        : cap master
  1612.  
  1613.       write("makemaster active\n")
  1614.       flush(stdout)
  1615.       mastercap:=create master(n) on myvm()
  1616.       if (mastercap = null) ->
  1617.      write("failed to create a master\n")
  1618.      flush(stdout)
  1619.      stop
  1620.       fi
  1621.       write("master created\n")
  1622.       flush(stdout)
  1623.       send who_is_master(mastercap)
  1624.    end makemaster
  1625.  
  1626. end main
  1627.  
  1628. From olsson@ivy.ucdavis.edu  Wed Oct 11 20:59:20 1989
  1629. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1630.     id AA13131; Wed, 11 Oct 89 20:59:20 MST
  1631. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  1632.     id AA11806; Wed, 11 Oct 89 21:01:30 PDT
  1633. Received: by ivy.ucdavis.edu (3.2/3.14)
  1634.     id AA15487; Wed, 11 Oct 89 20:58:14 PDT
  1635. Date: Wed, 11 Oct 89 20:58:14 PDT
  1636. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  1637. Message-Id: <8910120358.AA15487@ivy.ucdavis.edu>
  1638. To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  1639. Cc: info-sr@arizona.edu
  1640. In-Reply-To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU's message of Wed, 11 Oct 89 18:56:48 -0700 <8910120156.AA11305@awesome.berkeley.edu>
  1641. Subject: novice question
  1642.  
  1643.    Date: Wed, 11 Oct 89 18:56:48 -0700
  1644.    From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  1645.  
  1646.       I just installed SR on our SUNs and the first program I've tried,
  1647.       aside from existing examples, has me quite befuddled.
  1648.       ...
  1649.       It would appear that none of the sends or receives succeed.
  1650.  
  1651. The problem is simple.  main creates master by
  1652.  
  1653.      mastercap:=create master(n) on myvm()
  1654.  
  1655. Recall, however, that a create statement doesn't terminate until the
  1656. initial code in the resource instance it is creating completes.  The
  1657. essence of that code is
  1658.  
  1659.       initial
  1660.      fa i:=1 to n -> 
  1661.         receive handshake(num)
  1662.      af
  1663.      write("everyone is done.")
  1664.      stop
  1665.       end
  1666.  
  1667. But n>=1 and no slaves exist to send the master any handshakes, so
  1668. master hangs on the receive, thereby causing main to hang.  (The
  1669. reason no servants exist is that main's create statement has not yet
  1670. terminated, so main hasn't created the servants.)
  1671.  
  1672. Two easy fixes:
  1673.  
  1674. (1) change initial in master to be a process.  Then, master's initial
  1675. code is empty (except the implicit send to create that new process),
  1676. which terminates, allowing the create to terminate.
  1677.  
  1678. or (2) put a reply in master's initial.  I.e., 
  1679.  
  1680.       initial
  1681.      reply  # **** allower creator to continue
  1682.      fa i:=1 to n -> 
  1683.         receive handshake(num)
  1684.      af
  1685.      write("everyone is done.")
  1686.      stop
  1687.       end
  1688.  
  1689. I think (1) is clearer.
  1690.  
  1691. BTW, not such a novice problem.  I do this myself sometimes, and I've
  1692. seen a number of other people do the same.  We should put it on our
  1693. common problem list.
  1694.  
  1695. From mcnamee@iris.ucdavis.edu  Thu Oct 12 11:21:39 1989
  1696. Received: from clover.ucdavis.edu by megaron (5.59-1.7/15) via SMTP
  1697.     id AA19609; Thu, 12 Oct 89 11:21:39 MST
  1698. Received: from iris.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  1699.     id AA16179; Thu, 12 Oct 89 11:23:42 PDT
  1700. Received: by iris (5.57/3.14)
  1701.     id AA19802; Thu, 12 Oct 89 11:20:48 PDT
  1702. Date: Thu, 12 Oct 89 11:20:48 PDT
  1703. From: mcnamee@iris.ucdavis.edu (Carole McNamee)
  1704. Message-Id: <8910121820.AA19802@iris>
  1705. To: info-sr@arizona.edu
  1706. Subject: random number generator
  1707.  
  1708. Does anyone have an SR random number generator that produces "reasonable
  1709. sequences" ?
  1710. Thanks
  1711. C. McNamee
  1712.  
  1713. From gmt  Thu Oct 12 17:48:24 1989
  1714. Date: Thu, 12 Oct 89 17:48:24 MST
  1715. From: "Gregg Townsend" <gmt>
  1716. Message-Id: <8910130048.AA14749@megaron.arizona.edu>
  1717. Received: by megaron.arizona.edu (5.59-1.7/15)
  1718.     id AA14749; Thu, 12 Oct 89 17:48:24 MST
  1719. In-Reply-To: <8910121820.AA19802@iris>
  1720. To: mcnamee@iris.ucdavis.edu
  1721. Subject: Re:  random number generator
  1722. Cc: info-sr
  1723.  
  1724.     From: mcnamee@iris.ucdavis.edu (Carole McNamee)
  1725.     Date: Thu, 12 Oct 89 11:20:48 PDT
  1726.     
  1727.     Does anyone have an SR random number generator that produces
  1728.     "reasonable sequences" ?
  1729.     
  1730.  
  1731. If you're just looking to obtain random numbers in an SR program,
  1732. the easiest thing is to call the C library.  For example:
  1733.  
  1734.     resource x ()
  1735.         external getpid ()        returns n: int
  1736.         external random ()        returns n: int
  1737.         external srandom (seed: int)
  1738.     initial
  1739.         srandom(getpid())
  1740.         fa i := 1 to 10 -> write(random()) af
  1741.     end
  1742.     end
  1743.  
  1744. From mcnamee@iris.ucdavis.edu  Fri Oct 13 13:50:43 1989
  1745. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  1746.     id AA20715; Fri, 13 Oct 89 13:50:43 MST
  1747. Received: from iris.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  1748.     id AA23715; Fri, 13 Oct 89 13:52:59 PDT
  1749. Received: by iris (5.57/3.14)
  1750.     id AA16577; Fri, 13 Oct 89 11:58:25 PDT
  1751. Date: Fri, 13 Oct 89 11:58:25 PDT
  1752. From: mcnamee@iris.ucdavis.edu (Carole McNamee)
  1753. Message-Id: <8910131858.AA16577@iris>
  1754. To: gmt@arizona.edu, mcnamee@iris.ucdavis.edu
  1755. Subject: Re:  random number generator
  1756. Cc: info-sr@arizona.edu
  1757.  
  1758. Thanks for your response, unfortunately my question wasn't specific enough.
  1759. I need to be able to control the seed as I would like many processes to be
  1760. able to call the generator and I would like to guarrantee that each process
  1761. gets the same sequence each time it executes.  
  1762.  
  1763. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Tue Oct 17 10:22:53 1989
  1764. Received: from ucbvax.Berkeley.EDU by megaron (5.59-1.7/15) via SMTP
  1765.     id AA23606; Tue, 17 Oct 89 10:22:53 MST
  1766. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.38)
  1767.     id AA07466; Tue, 17 Oct 89 10:22:52 -0700
  1768. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  1769.     id AA18864; Tue, 17 Oct 89 10:24:23 PDT
  1770. Message-Id: <8910171724.AA18864@awesome.berkeley.edu>
  1771. To: info-sr@arizona.edu
  1772. Subject: compute server
  1773. Date: Tue, 17 Oct 89 10:24:21 -0700
  1774. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  1775.  
  1776.  
  1777. I have a few questions about SR, all relating to creating a "compute server".
  1778.  
  1779. First, here's an overview of what I'd like to set up.
  1780.  
  1781. The main machine M starts a compute server resource C and some number of
  1782. computing tasks A.  (These may actually be on different computers)
  1783. Each A has two processes.  One which does some computing and the another
  1784. which queries C to find another A which is "idle".  C keeps a list
  1785. of which A's are idle.
  1786.  
  1787.  
  1788. Questions:
  1789.  
  1790. (1)  How can an active resource determine its own capability?
  1791.      ie, how do I assign the proper value to "me" in the example below
  1792.  
  1793. resource X
  1794. body X
  1795.    var me : cap X
  1796.  
  1797. end X
  1798.  
  1799.  
  1800. (2)  What is the easiest way to cope with resources that are interdependent,
  1801.      ie resources that want to "import" each other.
  1802.      Is the following the only solution?
  1803.  
  1804. resource A_stub
  1805.    op something()
  1806. end A_stub
  1807.  
  1808. resource B
  1809.    import A_stub
  1810. body B
  1811. end B
  1812.  
  1813. resource A
  1814.    extend A_stub
  1815.    import B
  1816. body A
  1817. end A
  1818.  
  1819.  
  1820. (3) Is there some SR mechanism for "broadcasting"?  An alternative to the
  1821.     "compute server" would be that each A wanting to locate an idle A could
  1822.     just broadcast a request, and accept the first reply.  If this can
  1823.     be done, can it be done efficiently? (ie so resources don't have to keep
  1824.     responding to requests to say it is not idle)
  1825.  
  1826. (4) Below is an example (attempted) implementation and its output.
  1827. If you have the patience ...
  1828. Does anyone have any clues why it fails?  Also, any style suggestions would
  1829. be appreciated.  When I run the resulting program, there are two outcomes.
  1830.  
  1831. (source in ab.sr at the end)
  1832. awesome% srm
  1833. awesome% make
  1834. sr -c ab.sr
  1835. srl -o a.out compute ab main
  1836.  
  1837. awesome% a.out fugitive totally >& TMP
  1838. awesome% TMP
  1839. main: AB will be on: 
  1840. fugitive
  1841. totally
  1842. make: active
  1843. awesome : compute server ready
  1844. awesome : compute server starts
  1845. awesome : compute_idler starts
  1846. awesome : compute.number( 0 )
  1847. make: compute created, machine ID is  0
  1848. make: about to create AB
  1849. make: creating AB on  fugitive
  1850. fugitive : ab initial
  1851. make: AB  1  has machine id  1
  1852. fugitive : ap_spawner, waiting for my cap
  1853. fugitive : ab_server
  1854. fugitive : ab.number( 1 )
  1855. [vm 2] RTS abort: attempting to invoke operation that no longer exists
  1856.  
  1857. awesome% a.out fugitive totally
  1858. main: AB will be on: 
  1859. fugitive
  1860. totally
  1861. make: active
  1862. awesome : compute server ready
  1863. awesome : compute server starts
  1864. awesome : compute_idler starts
  1865. awesome : compute.number( 0 )
  1866. make: compute created, machine ID is  0
  1867. make: about to create AB
  1868. make: creating AB on  fugitive
  1869. fugitive : ab initial
  1870. fugitive : ap_spawner, waiting for my cap
  1871. fugitive : ab_server
  1872. make: AB  1  has machine id  1
  1873. fugitive : ab.number( 1 )
  1874. srx: can't connect to vm 32 -- not yet initialized
  1875.  
  1876. ---------------------------- ab.sr ----------------------------
  1877. /* AB */
  1878.  
  1879. resource ab_basics
  1880.    op ab_reply(m:cap ab_basics) 
  1881.    op ab_yourcap(m:cap ab_basics)
  1882.    op ab_work(h:string(100); m:cap ab_basics)
  1883.    op ab_work_done()
  1884.    op number() returns n : int
  1885.    external gethostname(res name:string(*); namelen:int)
  1886. end ab_basics
  1887.  
  1888. resource compute
  1889.    import ab_basics
  1890.    op    compute_request(m:cap ab_basics)
  1891.    op    compute_done(m:cap ab_basics)
  1892.    op    compute_unlock()
  1893.    op    compute_lock()
  1894.    op    compute_machines(m[1:*]:cap ab_basics)
  1895.    op    number() returns n:int
  1896.    external gethostname(res name:string(*); namelen:int)
  1897. body compute(n:int)
  1898.    var    h            :string(100)
  1899.    var    machine[1:n]        :cap ab_basics
  1900.    var    idle[1:n]        :int
  1901.    var    n_idle            :int
  1902.    var    index            :int
  1903.  
  1904.    initial
  1905.       call gethostname(h,maxlength(h))
  1906.       fa i:=1 to n ->
  1907.      idle[i]:=1
  1908.       af
  1909.       index:=1
  1910.       n_idle:=n
  1911.       write(h,": compute server ready") flush(stdout)
  1912.    end
  1913.  
  1914.    proc number() returns n
  1915.       n:=mymachine()
  1916.       write(h,": compute.number(",n,")") flush(stdout)
  1917.       flush(stdout)
  1918.    end number
  1919.  
  1920.    process compute_lock_server
  1921.       do (true) ->
  1922.          send compute_unlock()
  1923.          receive compute_lock()
  1924.       od
  1925.    end compute_lock_server
  1926.  
  1927.    process compute_server
  1928.       var r            :cap ab_basics
  1929.  
  1930.       write(h,": compute server starts") flush(stdout)
  1931.       receive compute_machines(machine)
  1932.       write(h,": compute server knows machines") flush(stdout)
  1933.       do (true) ->
  1934.          do (n_idle < 1) ->
  1935.         write(h,": computer server sleeping") flush(stdout)
  1936.         nap(5000)
  1937.          od
  1938.          receive compute_request(r)
  1939.      receive compute_unlock()
  1940.          fa i:=1 to n ->
  1941.         if (idle[index] > 0) ->
  1942.            send r.ab_reply(machine[i])
  1943.            idle[i]:=0
  1944.         fi
  1945.         index++
  1946.         if (index > n) ->
  1947.            index:=1
  1948.         fi
  1949.      af
  1950.      send compute_lock()
  1951.       od
  1952.    end compute_server
  1953.  
  1954.    process compute_idler
  1955.       var m            :cap ab_basics
  1956.  
  1957.       write(h,": compute_idler starts") flush(stdout)
  1958.       do (true) ->
  1959.          receive compute_done(m)
  1960.      receive compute_unlock()
  1961.      fa i:=1 to n ->
  1962.         if (m = machine[i]) ->
  1963.            write(h,": compute idler, ",i," becomes idle\n") flush(stdout)
  1964.            idle[i]:=1
  1965.            exit
  1966.         fi
  1967.      af
  1968.      send compute_lock()
  1969.       od
  1970.    end compute_idler
  1971.  
  1972. end compute
  1973.  
  1974.  
  1975. resource ab
  1976.    extend ab_basics
  1977.    import compute
  1978. body ab(c:cap compute)
  1979.    var    h            :string(100)
  1980.    var    mycap            :cap ab
  1981.  
  1982.    initial
  1983.       gethostname(h,maxlength(h))
  1984.       write(h,": ab initial") flush(stdout)
  1985.       flush(stdout)
  1986.    end
  1987.  
  1988.    proc number() returns n
  1989.       n:=mymachine()
  1990.       write(h,": ab.number(",n,")") flush(stdout)
  1991.       flush(stdout)
  1992.    end number
  1993.  
  1994.    process ab_spawner
  1995.       var m            :cap ab
  1996.  
  1997.       write(h,": ap_spawner, waiting for my cap") flush(stdout)
  1998.       receive ab_yourcap(mycap)
  1999.       write(h,": ab_spawner, sleeping") flush(stdout)
  2000.       nap(4000)
  2001.       send c.compute_request(mycap)
  2002.       receive ab_reply(m)
  2003.       send m.ab_work(h,mycap)
  2004.       receive ab_work_done()
  2005.       send c.compute_done(m)
  2006.    end ab_spawner
  2007.  
  2008.    process ab_server
  2009.       var host            :string(100)
  2010.       var m            :cap ab
  2011.  
  2012.       write(h,": ab_server") flush(stdout)
  2013.       do (true) ->
  2014.          receive ab_work(host,m)
  2015.          write(h,": ab_server gets work from ",host," - sleeping") flush(stdout)
  2016.      nap(10000)
  2017.      send m.ab_work_done()
  2018.          write(h,": ab_server done") flush(stdout)
  2019.       od
  2020.    end ab_server
  2021.  
  2022.    final
  2023.       write(h,": ab final") flush(stdout)
  2024.    end
  2025. end ab
  2026.  
  2027.  
  2028. resource main
  2029.    import compute
  2030.    import ab
  2031. body main()
  2032.    var  n            :int
  2033.    var    ab_cap[1:n]        :cap ab
  2034.  
  2035.    initial
  2036.       var s            :string(100)
  2037.  
  2038.       n:=numargs()
  2039.       write("main: AB will be on: ")
  2040.       fa i:=1 to n ->
  2041.      getarg(i,s)
  2042.      write(s)
  2043.       af
  2044.       flush(stdout)
  2045.    end
  2046.  
  2047.    process make
  2048.       var s            :string(100)
  2049.       var remote        :cap vm
  2050.       var c            :cap compute
  2051.  
  2052.       write("make: active") flush(stdout)
  2053.       c:=create compute(n) on myvm()
  2054.       if (c = null) ->
  2055.      write("make: failed to create a compute") flush(stdout)
  2056.      stop
  2057.       fi
  2058.       write("make: compute created, machine ID is ",c.number()) flush(stdout)
  2059.       write("make: about to create AB") flush(stdout)
  2060.       fa i := 1 to n ->
  2061.      getarg(i,s)
  2062.      locate(i,s)
  2063.      remote:=create vm() on i
  2064.      if (remote = null) ->
  2065.         write(stderr,"make_ab: can't create vm on",s) flush(stderr)
  2066.      [] else ->
  2067.         write("make: creating AB on ",s) flush(stdout)
  2068.         ab_cap[i]:=create ab(c) on remote
  2069.         if (ab_cap[i] = null) ->
  2070.            write("make: create AB on host ",s,", machine ",i," failed.")
  2071.            flush(stdout)
  2072.         [] else ->
  2073.            write("make: AB ",i," has machine id ",ab_cap[i].number())
  2074.            flush(stdout)
  2075.            send ab_cap[i].ab_yourcap(ab_cap[i])
  2076.            write("make: AB notified of its cap")
  2077.         fi
  2078.      fi
  2079.       af
  2080.       write("make: all AB created, sleeping") flush(stdout)
  2081.       nap(10000)
  2082.       write("make: telling server which machines") flush(stdout)
  2083.       send c.compute_machines(ab_cap)
  2084.    end make
  2085.  
  2086.    final
  2087.       write("main: cleanup") flush(stdout)
  2088.    end
  2089. end main
  2090.  
  2091.  
  2092. From olsson@ivy.ucdavis.edu  Wed Oct 18 12:02:27 1989
  2093. Received: from clover.ucdavis.edu by megaron (5.59-1.7/15) via SMTP
  2094.     id AA13484; Wed, 18 Oct 89 12:02:27 MST
  2095. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  2096.     id AA22058; Tue, 17 Oct 89 21:03:21 PDT
  2097. Received: by ivy.ucdavis.edu (3.2/3.14)
  2098.     id AA27368; Tue, 17 Oct 89 20:59:31 PDT
  2099. Date: Tue, 17 Oct 89 20:59:31 PDT
  2100. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  2101. Message-Id: <8910180359.AA27368@ivy.ucdavis.edu>
  2102. To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2103. Cc: info-sr@arizona.edu
  2104. In-Reply-To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU's message of Tue, 17 Oct 89 10:24:21 -0700 <8910171724.AA18864@awesome.berkeley.edu>
  2105. Subject: compute server
  2106.  
  2107.    Date: Tue, 17 Oct 89 10:24:21 -0700
  2108.    From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2109.    ...
  2110.    Questions:
  2111.  
  2112.    (1)  How can an active resource determine its own capability?
  2113.     ie, how do I assign the proper value to "me" in the example below
  2114.  
  2115.    resource X
  2116.    body X
  2117.       var me : cap X
  2118.  
  2119.    end X
  2120.  
  2121. me := myresource()  (See section 7.5 in the report.)
  2122.  
  2123.    (2)  What is the easiest way to cope with resources that are interdependent,
  2124.     ie resources that want to "import" each other.
  2125.     Is the following the only solution?
  2126.  
  2127. Maybe not the only one, but a reasonable one.  There was a discussion
  2128. on info-sr about 2 months ago on this topic; I'll send it to you.
  2129. That is a lacking in SR -- something we are remedying in version 2.
  2130.  
  2131.    (3) Is there some SR mechanism for "broadcasting"?  An alternative to the
  2132.        "compute server" would be that each A wanting to locate an idle A could
  2133.        just broadcast a request, and accept the first reply.  If this can
  2134.        be done, can it be done efficiently? (ie so resources don't have to keep
  2135.        responding to requests to say it is not idle)
  2136.  
  2137. I didn't take time to look at your application in detail.  However,
  2138. you might use a co statement, e.g.,
  2139.  
  2140.     co (i := 1 to N) Acap[i].try -> got := i; exit  oc
  2141.  
  2142. That will broadcast a request to all in Acap, and continue when one of
  2143. them replies, recording that index in got.  (You might then use
  2144. Acap[got].otherop(...) to invoke otherop in Acap[got].)
  2145.  
  2146.    (4) Below is an example (attempted) implementation and its output.
  2147.    If you have the patience ...
  2148.    Does anyone have any clues why it fails?
  2149.  
  2150. I see one big problem, but I haven't tried running a corrected version.
  2151.  
  2152.    resource main
  2153.       import compute
  2154.       import ab
  2155.    body main()
  2156.       var  n            :int
  2157.       var    ab_cap[1:n]        :cap ab
  2158.  
  2159. ab_cap is allocated with the current value of n, which at this point
  2160. is garbage.  (It isn't initialized until below in initial.)
  2161.  
  2162.       initial
  2163.      var s            :string(100)
  2164.  
  2165.      n:=numargs()
  2166.      write("main: AB will be on: ")
  2167.      fa i:=1 to n ->
  2168.         getarg(i,s)
  2169.         write(s)
  2170.      af
  2171.      flush(stdout)
  2172.       end
  2173.  
  2174. Two possible fixes:
  2175.  
  2176. (1) change declaration of n to (and delete assignment to n in initial)
  2177.  
  2178.     var n :int := numargs()
  2179.  
  2180. (2) move declaration of ab_cap to process make (i.e., after initial
  2181. has executed and set n).
  2182.  
  2183. I didn't try running your program with these fixes, so it might have
  2184. other problems too.
  2185.  
  2186. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Thu Oct 19 10:11:57 1989
  2187. Received: from ucbvax.Berkeley.EDU by megaron (5.59-1.7/15) via SMTP
  2188.     id AA19777; Thu, 19 Oct 89 10:11:57 MST
  2189. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.38)
  2190.     id AA07152; Thu, 19 Oct 89 10:11:34 -0700
  2191. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  2192.     id AA21372; Wed, 18 Oct 89 15:18:22 PDT
  2193. Message-Id: <8910182218.AA21372@awesome.berkeley.edu>
  2194. To: info-sr@arizona.edu
  2195. Subject: trouble passing "capabilities" 
  2196. Date: Wed, 18 Oct 89 15:18:21 -0700
  2197. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2198.  
  2199.  
  2200. I am having trouble passing "capabilities" around between processes
  2201. in different resources.  The following example is a stripped version
  2202. of a larger one in which several active resources query a "compute server"
  2203. and are returned the "capability" of an idle resource (machine), to which
  2204. some work can be sent.
  2205.  
  2206.  
  2207. ----- synopsis of what is in "simple.sr" at end of this message -----
  2208.  
  2209. MAIN creates B
  2210. MAIN creates A (telling it who B is)
  2211. MAIN informs B who A is
  2212.  
  2213. B pings A to check it is there
  2214.  
  2215. A asks B for some "other" A which it can ping
  2216.  
  2217. B replies to A
  2218.  
  2219. A tries to ping and fails.
  2220.  
  2221. The value returned to A seems invalid, despite the fact that B just used it
  2222. in the same way A is trying to.
  2223.  
  2224.  
  2225. ----- output -----
  2226.  
  2227. % a.out awesome totally
  2228.  
  2229. make: b created
  2230. make: a created
  2231. a_caller: waiting for a reply to request
  2232. make: informing b
  2233. a: I got pinged
  2234. b_server: received request
  2235. a_caller: about to ping machine returned by b
  2236. b_server: replied
  2237. [vm 3] RTS abort: attempting to invoke null operation
  2238.  
  2239. (does "vm 3" give a clue?  As far as I can tell, 0, 1, 2 are active, not 3.)
  2240. %
  2241.  
  2242. ----- simple.sr -----
  2243.  
  2244. resource a_stub
  2245.    op a_reply(a_stub_cap:cap a_stub)
  2246.    op a_ping()
  2247. end a_stub
  2248.  
  2249. resource b
  2250.    import a_stub
  2251.    op b_request(a_stub_cap:cap a_stub)
  2252.    op b_inform(a_stub_cap:cap a_stub)
  2253. body b()
  2254.    process b_server
  2255.       var a_stub_cap        :cap a_stub
  2256.       var remote        :cap a_stub
  2257.  
  2258.       receive b_inform(a_stub_cap)
  2259.       call a_stub_cap.a_ping()
  2260.       receive b_request(remote)
  2261.       write("b_server: received request") flush(stdout) nap(1000)
  2262.       send remote.a_reply(a_stub_cap)
  2263.       write("b_server: replied") flush(stdout) nap(1000)
  2264.    end b_server 
  2265. end b
  2266.  
  2267.  
  2268. resource a
  2269.    extend a_stub
  2270.    import b
  2271. body a(b_cap:cap b)
  2272.  
  2273.    proc a_ping()
  2274.       write("a: I got pinged") flush(stdout) nap(1000)
  2275.    end a_ping
  2276.  
  2277.    process a_caller
  2278.       var other            :cap a
  2279.  
  2280.       send b_cap.b_request(myresource())
  2281.       write("a_caller: waiting for a reply to request") flush(stdout) nap(1000)
  2282.       receive a_reply(other)
  2283.       write("a_caller: about to ping machine returned by b") flush(stdout) nap(1000)
  2284.       call other.a_ping()
  2285.       write("a_caller: other A appears to be alive") flush(stdout)
  2286.    end a_caller
  2287. end a
  2288.  
  2289.  
  2290. resource main
  2291.    import a
  2292.    import b
  2293. body main()
  2294.    initial
  2295.       if (numargs() != 2) ->
  2296.      stop
  2297.       fi
  2298.    end
  2299.  
  2300.    process make
  2301.       var hostname        :string(100)
  2302.       var a_cap            :cap a
  2303.       var b_cap            :cap b
  2304.       var remote        :cap vm
  2305.  
  2306.       getarg(1,hostname)
  2307.       locate(1,hostname)
  2308.       remote:=create vm() on 1
  2309.       if (remote = null) ->
  2310.      write("make: can't create vm on ",hostname) flush(stdout)
  2311.      stop
  2312.       fi
  2313.       b_cap:=create b() on remote
  2314.       if (b_cap = null) ->
  2315.      write("make: can't create B on ",hostname) flush(stdout)
  2316.      stop
  2317.       fi
  2318.       write("make: b created") flush(stdout) nap(1000)
  2319.  
  2320.       getarg(2,hostname)
  2321.       locate(2,hostname)
  2322.       remote:=create vm() on 2
  2323.       if (remote = null) ->
  2324.      write("make: can't create vm on ",hostname) flush(stdout)
  2325.      stop
  2326.       fi
  2327.       a_cap:=create a(b_cap) on remote
  2328.       if (a_cap = null) ->
  2329.      write("make: can't create A on ",hostname) flush(stdout)
  2330.      stop
  2331.       fi
  2332.       write("make: a created") flush(stdout) nap(1000)
  2333.  
  2334.       write("make: informing b") flush(stdout) nap(1000)
  2335.       send b_cap.b_inform(a_cap)
  2336.    end make
  2337. end main
  2338.  
  2339.  
  2340. From olsson@ivy.ucdavis.edu  Fri Oct 20 11:27:55 1989
  2341. Received: from clover.ucdavis.edu by megaron (5.59-1.7/15) via SMTP
  2342.     id AA10089; Fri, 20 Oct 89 11:27:55 MST
  2343. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  2344.     id AA11898; Fri, 20 Oct 89 11:30:26 PDT
  2345. Received: by ivy.ucdavis.edu (3.2/3.14)
  2346.     id AA05185; Fri, 20 Oct 89 11:26:20 PDT
  2347. Date: Fri, 20 Oct 89 11:26:20 PDT
  2348. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  2349. Message-Id: <8910201826.AA05185@ivy.ucdavis.edu>
  2350. To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2351. Cc: info-sr@arizona.edu
  2352. In-Reply-To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU's message of Wed, 18 Oct 89 15:18:21 -0700 <8910182218.AA21372@awesome.berkeley.edu>
  2353. Subject: trouble passing "capabilities" 
  2354.  
  2355.    Date: Wed, 18 Oct 89 15:18:21 -0700
  2356.    From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2357.  
  2358.    I am having trouble passing "capabilities" around between processes
  2359.    ...
  2360.  
  2361. You've discovered a new bug, sorry to say.  It seems to be caused by
  2362. extending a resource that contains a capability for itself.  In your
  2363. program that happens
  2364.  
  2365.    resource a_stub
  2366.       op a_reply(a_stub_cap:cap a_stub)
  2367.       op a_ping()
  2368.    end a_stub
  2369.    ...
  2370.    resource a
  2371.       extend a_stub
  2372.       import b
  2373.    body a(b_cap:cap b)
  2374.       process a_caller
  2375.      var other            :cap a
  2376.      send b_cap.b_request(myresource())
  2377.      write("a_caller: waiting for a reply to request") ...
  2378.      receive a_reply(other)
  2379.      write("a_caller: about to ping machine returned by b") ...
  2380.      call other.a_ping()
  2381.      write("a_caller: other A appears to be alive") flush(stdout)
  2382.       end a_caller
  2383.    end a
  2384.  
  2385. The exact problem is that we generate bad code for `receive
  2386. a_reply(other)'; it doesn't set other's value correctly.  In
  2387. particular, we don't copy into other, so by chance other's value is
  2388. null and the program dies on the call.
  2389.  
  2390. The workaround is to not use the extend.  Replace extend with the
  2391. equivalent definitions (and change caps for the extended resource to
  2392. caps for the current one).  E.g., change your program to the following.
  2393.  
  2394. resource a_stub
  2395.    op a_reply(a_stub_cap:cap a_stub)
  2396.    op a_ping()
  2397. end a_stub
  2398.  
  2399. resource b
  2400.    import a_stub
  2401.    op b_request(a_stub_cap:cap a_stub)
  2402.    op b_inform(a_stub_cap:cap a_stub)
  2403. body b()
  2404.    process b_server
  2405.       var a_stub_cap        :cap a_stub
  2406.       var remote        :cap a_stub
  2407.  
  2408.       receive b_inform(a_stub_cap)
  2409.       call a_stub_cap.a_ping()
  2410.       receive b_request(remote)
  2411.       write("b_server: received request") flush(stdout) nap(1000)
  2412.       send remote.a_reply(a_stub_cap)
  2413.       write("b_server: replied") flush(stdout) nap(1000)
  2414.    end b_server 
  2415. end b
  2416.  
  2417.  
  2418. resource a
  2419. #   extend a_stub
  2420.    op a_reply(a_stub_cap:cap a)
  2421.    op a_ping()
  2422.    import b
  2423. body a(b_cap:cap b)
  2424.    proc a_ping()
  2425.       write("a: I got pinged") flush(stdout) nap(1000)
  2426.    end a_ping
  2427.    process a_caller
  2428.       var other    :cap a
  2429.       send b_cap.b_request(myresource())
  2430.       write("a_caller: waiting for a reply to request") flush(stdout) nap(1000)
  2431.       receive a_reply(other)
  2432. #
  2433. # bogus generated code uses memcpy(_,_,0) to copy into other for receive.
  2434. #
  2435.       write("a_caller: about to ping machine returned by b") flush(stdout) nap(1000)
  2436. if other = noop -> write("other is noop")
  2437. [] other = null -> write("other is null")
  2438. [] else -> write("other is ok")
  2439. fi
  2440.       call other.a_ping()
  2441.       write("a_caller: other A appears to be alive") flush(stdout)
  2442.    end a_caller
  2443. end a
  2444.  
  2445.  
  2446. resource main
  2447.    import a
  2448.    import b
  2449. body main()
  2450.    process make
  2451.       var a_cap    :cap a
  2452.       var b_cap    :cap b
  2453.       b_cap:=create b()
  2454.       write("make: b created") flush(stdout) nap(1000)
  2455.       a_cap:=create a(b_cap)
  2456.       write("make: a created") flush(stdout) nap(1000)
  2457.       send b_cap.b_inform(a_cap)
  2458.       write("make: b informed") flush(stdout) nap(1000)
  2459.    end make
  2460. end main
  2461.  
  2462.  
  2463. From gmt  Thu Oct 26 17:43:29 1989
  2464. Date: Thu, 26 Oct 89 17:43:29 MST
  2465. From: "Gregg Townsend" <gmt>
  2466. Message-Id: <8910270043.AA13081@megaron.arizona.edu>
  2467. Received: by megaron.arizona.edu (5.59-1.7/15)
  2468.     id AA13081; Thu, 26 Oct 89 17:43:29 MST
  2469. To: info-sr
  2470. Subject: New Context Switch Code for Sun-4 Systems
  2471.  
  2472. Several ill-defined runtime problems have been reported when running SR
  2473. on the SPARC (Sun4) architecture.  The context switching code (rts/sparc.s)
  2474. is believed to be responsible.
  2475.  
  2476. Below is an alternate implementation of context switching for Sun4 systems.
  2477. This code uses the Sun lightweight process library and should be used in
  2478. place of the current assembly language code.
  2479.  
  2480. Use of this code requires three minor changes in the SR source file hierarchy:
  2481.  
  2482.     1.    Install the code below in a new file "rts/sunlwp.c".
  2483.  
  2484.     2.  Edit "rts/Makefile" and change the first mention of "machine.o"
  2485.     (in the definition of OBJ) to "sunlwp.o".
  2486.  
  2487.     3.  Edit "srl/gen.c" and insert a line
  2488.         *argp++ = "-llwp";
  2489.     five lines before the end of file, immediately before the line
  2490.         *argp++ = 0;
  2491.  
  2492. After making those changes, just build or rebuild SR in the usual manner
  2493. as described in the installation documentation.
  2494.  
  2495. This code will also run on Sun3 systems, but we do not recommend installing
  2496. it there because it is slower than the existing code.
  2497.  
  2498.     Gregg Townsend / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  2499.     +1 602 621 4325     gmt@cs.arizona.edu     110 57 16 W / 32 13 45 N / +761m
  2500.  
  2501.  
  2502. ---------------------- cut here, save as rts/sunlwp.c  ----------------------
  2503.  
  2504.  
  2505.  
  2506. /*  sunlwp.c - SR context switching routines using Sun lightweight processes  */
  2507.  
  2508.  
  2509.  
  2510. #include <stdio.h>
  2511. #include <lwp/lwp.h>
  2512. #include <lwp/stackdep.h>
  2513.  
  2514. #define CON_MAGIC 2079447381    /* an arbitrary (and unlikely) magic number */
  2515.  
  2516. #define GOOD_PRI 2        /* priority for real threads */
  2517. #define KILL_PRI 1        /* priority for the killer thread */
  2518. #define KILL_STK 512        /* stack size for killer thread */
  2519.  
  2520. #define lwcall(text,retval) if ((retval) != 0) lwerror (text);
  2521.  
  2522.  
  2523.  
  2524. typedef struct {        /* context header: */
  2525.     thread_t tid;        /*   thread id for lwp library */
  2526.     int magic;            /*   magic number for integrity checking */
  2527. } con_hdr, *con_ptr;
  2528.  
  2529.  
  2530. static con_ptr curr;        /* current context pointer */
  2531.  
  2532. static void startup(), initkiller(), killer(), lwerror();
  2533.  
  2534.  
  2535.  
  2536.  
  2537. /*************************  EXTERNAL ROUTINES  *************************/
  2538.  
  2539.  
  2540.  
  2541. /*  sr_build_context - create a new SR process context.
  2542.  *
  2543.  *  We put a context header (see above) at the beginning of the space
  2544.  *  and use the rest for the lwp stack.
  2545.  */
  2546.  
  2547. void
  2548. sr_build_context (entry, context, size, arg1, arg2, arg3, arg4)
  2549. void (*entry)();
  2550. char *context;
  2551. int size;
  2552. int arg1, arg2, arg3, arg4;
  2553. {
  2554.     static int first = 1;        /* first-call flag */
  2555.     con_ptr cp = (con_ptr) context;    /* context pointer */
  2556.  
  2557.     /* initialize a few things the first time we're called */
  2558.     if (first) {
  2559.     lwcall("set maxpri", pod_setmaxpri (GOOD_PRI));    /* set priority range */
  2560.     initkiller ();                    /* init killer thread */
  2561.     first = 0;                    /* note init done */
  2562.     }
  2563.  
  2564.     cp = (con_ptr) context;        /* get context block pointer */
  2565.     if (cp->magic == CON_MAGIC)        /* if reusing stack, kill previous */
  2566.     lwcall("destroy lwp", lwp_destroy (cp->tid));
  2567.     lwcall("create lwp",        /* create new thread */
  2568.     lwp_create (&cp->tid, startup, GOOD_PRI, LWPSUSPEND + LWPNOLASTRITES,
  2569.         context + size, 5, entry, arg1, arg2, arg3, arg4));
  2570.     cp->magic = CON_MAGIC;        /* set magic word for stack checking */
  2571. }
  2572.  
  2573.  
  2574.  
  2575. /*  sr_chg_context() - switch to a different SR process  */
  2576.  
  2577. void
  2578. sr_chg_context (context)
  2579. char *context;
  2580. {
  2581.     con_ptr cp = (con_ptr) context;
  2582.  
  2583.     if (curr != 0 && curr->magic != CON_MAGIC)    /* check curr stk looks good */
  2584.     sr_stk_overflow ();
  2585.     if (cp == curr)            /* nothing to do on change to self */
  2586.     return;
  2587.     if (cp->magic != CON_MAGIC)        /* check that new stack looks good */
  2588.     sr_stk_corrupted ();
  2589.     lwcall("resume", lwp_resume (cp->tid));    /* unsuspend new process */
  2590.     curr = cp;                    /* remember current pointer */
  2591.     lwcall("suspend", lwp_suspend (SELF));    /* suspend self, yield to new */
  2592. }
  2593.  
  2594.  
  2595.  
  2596. /*  sr_check_stk() - check for stack overflow.
  2597.  *
  2598.  *  We check to see if the magic word has been overwritten.
  2599.  *  This isn't foolproof, but it will catch some errors.
  2600.  */
  2601.  
  2602. void
  2603. sr_check_stk ()
  2604. {
  2605.     if (curr->magic != CON_MAGIC)
  2606.     sr_stk_overflow ();
  2607. }
  2608.  
  2609.  
  2610.  
  2611.  
  2612. /*************************  INTERNAL ROUTINES  *************************/
  2613.  
  2614.  
  2615.  
  2616. /*  startup() - call the entry point of a newly created SR process.
  2617.  *
  2618.  *  If it ever returns, signal stack underflow.
  2619.  */
  2620.  
  2621. static void
  2622. startup (entry, arg1, arg2, arg3, arg4)
  2623. void (*entry)();
  2624. int arg1, arg2, arg3, arg4;
  2625. {
  2626.     (*entry) (arg1, arg2, arg3, arg4);
  2627.     sr_stk_underflow ();
  2628. }
  2629.  
  2630.  
  2631.  
  2632. /*  initkiller() - set up a thread to catch exit calls.
  2633.  *
  2634.  *  The problem is that exit() is caught by the lwp library and doesn't
  2635.  *  really exit; so, we create a low-priority killer thread that will do so.
  2636.  *  If the executing SR process exits, the killer thread will get control
  2637.  *  because all other SR processes are still suspended.
  2638.  */
  2639.  
  2640. static void
  2641. initkiller ()
  2642. {
  2643.     thread_t tid;
  2644.     static char killstk[KILL_STK];
  2645.  
  2646.     lwcall("create killer",
  2647.     lwp_create (&tid, killer, KILL_PRI, LWPNOLASTRITES,
  2648.         killstk + KILL_STK, 0));
  2649. }
  2650.  
  2651.  
  2652.  
  2653. /*  killer() - the actual code executed by the killer thread.  */
  2654.  
  2655. static void
  2656. killer ()
  2657. {
  2658.     pod_exit (pod_getexit ());
  2659. }
  2660.  
  2661.  
  2662.  
  2663. /*  lwerror(text) - abort with message from lightweight process error  */
  2664.  
  2665. static void
  2666. lwerror (text)
  2667. char *text;
  2668. {
  2669.     fprintf (stderr, "lwp error: ");
  2670.     lwp_perror (text);
  2671.     pod_exit (1);
  2672. }
  2673.  
  2674. From bina@acsu.buffalo.edu  Sun Nov  5 13:07:08 1989
  2675. Received: from autarch.acsu.buffalo.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2676.     id AA01515; Sun, 5 Nov 89 13:07:08 MST
  2677. Received: by autarch.acsu.buffalo.edu (4.0/1.35)
  2678.     id AA12226; Sun, 5 Nov 89 15:07:06 EST
  2679. Date: Sun, 5 Nov 89 15:07:06 EST
  2680. From: bina@acsu.buffalo.edu (Bina Ramamurthy)
  2681. Message-Id: <8911052007.AA12226@autarch.acsu.buffalo.edu>
  2682. To: info-sr@cs.arizona.edu
  2683. Subject: want info
  2684.  
  2685.  
  2686. I am an instructor at SUNY Buffalo. I am interested in knowing
  2687. whether you are using SR in any of your regular undergraduate
  2688. courses like operating systems, computer architecture.
  2689.  
  2690. Could you also give me list of all the courses using SR and
  2691. the hardware set up (what king machines etc.) you are using
  2692. it on?
  2693.  
  2694. bina
  2695.  
  2696. bina@gort.cc.buffalo.edu
  2697.  
  2698. From greg  Sun Nov  5 19:11:10 1989
  2699. Received: from paloverde.cs.arizona.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2700.     id AA13131; Sun, 5 Nov 89 19:11:10 MST
  2701. Date: Sun, 5 Nov 89 19:10:59 MST
  2702. From: "Greg Andrews" <greg>
  2703. Message-Id: <8911060210.AA08615@paloverde>
  2704. Received: by paloverde; Sun, 5 Nov 89 19:10:59 MST
  2705. In-Reply-To: <8911052007.AA12226@autarch.acsu.buffalo.edu>
  2706. To: bina@acsu.buffalo.edu
  2707. Subject: Re:  want info
  2708. Cc: info-sr
  2709.  
  2710. We are not yet using SR in any undergraduate courses.
  2711. (We just began an undergraduate major this year so do
  2712. not have as many undergraduate courses as we eventually
  2713. will.)
  2714.  
  2715. SR is used for all programming projects in our
  2716. course on concurrent programming.  It is also used -- typically
  2717. at student discretion -- in graduate courses on operating
  2718. systems, networks, and parallel algorithms.  It has also been
  2719. used in a course on logic programming (two students used SR
  2720. to implement an interpreter for a variant of concurrent Prolog).
  2721. By student discretion I mean that use of SR is not required;
  2722. instead some students who already know it choose to do their
  2723. course projects in SR.
  2724.  
  2725. For your information, Ron Olsson and I are writing a book
  2726. "Concurrent Programming in SR" to be published in 1991 by
  2727. Benjamin/Cummings.  If you are interested in using SR for
  2728. classroom projects, this should make it a *lot* easier on
  2729. you and your students.  Also, we will have a second (much
  2730. improved naturally) version of SR out in a year -- and the
  2731. book will describe that version.
  2732.  
  2733. -- Greg Andrews
  2734.  
  2735. From bina@cs.Buffalo.EDU  Mon Nov  6 08:02:16 1989
  2736. Received: from gort.cs.Buffalo.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2737.     id AA08071; Mon, 6 Nov 89 08:02:16 MST
  2738. Received: by gort.cs.Buffalo.EDU (5.61/1.01)
  2739.     id AA19585; Mon, 6 Nov 89 10:02:17 -0500
  2740. Date: Mon, 6 Nov 89 10:02:17 -0500
  2741. From: bina@cs.Buffalo.EDU (Bina Ramamurthy)
  2742. Message-Id: <8911061502.AA19585@gort.cs.Buffalo.EDU>
  2743. To: bina@acsu.buffalo.edu, greg@cs.arizona.edu
  2744. Subject: Re:  want info
  2745. Cc: info-sr@cs.arizona.edu
  2746.  
  2747. Thanks. Let me try the version of SR we have and then
  2748. write to you if I have any questions.
  2749.  
  2750. bina
  2751.  
  2752. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Sat Nov 18 01:04:00 1989
  2753. Received: from ucbvax.Berkeley.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2754.     id AA12117; Sat, 18 Nov 89 01:04:00 MST
  2755. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.39)
  2756.     id AA17598; Sat, 18 Nov 89 00:03:19 -0800
  2757. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  2758.     id AA09410; Sat, 18 Nov 89 00:05:23 PST
  2759. Message-Id: <8911180805.AA09410@awesome.berkeley.edu>
  2760. To: info-sr@arizona.edu
  2761. Subject: string(*) vs string(100)
  2762. Date: Sat, 18 Nov 89 00:05:22 -0800
  2763. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2764.  
  2765. What is the difference between :
  2766.     op ping(from:string(*); to:string(*))
  2767. and
  2768.     op ping(from:string(100); res to:string(100))
  2769.  
  2770.  
  2771. when they will be implemented as
  2772.  
  2773.     var myhost:string(100)
  2774.     initial
  2775.        gethostname(myhost,maxlength(myhost))
  2776.     end initial
  2777.     proc ping(from,to)
  2778.        write("pinged by",from)
  2779.        to:=myhost
  2780.     end ping
  2781.  
  2782.  
  2783.     ...
  2784.     var other_host:string(100)
  2785.     call other_machine.ping(myhost,other_host)
  2786.     write(other_host,"is alive")
  2787.  
  2788. David Jones
  2789. djones@awesome.berkeley.edu
  2790.  
  2791. From olsson@ivy.ucdavis.edu  Sat Nov 18 02:17:02 1989
  2792. Received: from clover.ucdavis.edu by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2793.     id AA16340; Sat, 18 Nov 89 02:17:02 MST
  2794. Received: from ivy.ucdavis.edu by clover.ucdavis.edu (5.59/UCD.EECS.1.11)
  2795.     id AA03245; Sat, 18 Nov 89 01:18:32 PST
  2796. Received: by ivy.ucdavis.edu (3.2/3.14)
  2797.     id AA27610; Sat, 18 Nov 89 01:16:47 PST
  2798. Date: Sat, 18 Nov 89 01:16:47 PST
  2799. From: olsson@ivy.ucdavis.edu (Ron Olsson)
  2800. Message-Id: <8911180916.AA27610@ivy.ucdavis.edu>
  2801. To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2802. Cc: info-sr@cs.arizona.edu
  2803. In-Reply-To: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU's message of Sat, 18 Nov 89 00:05:22 -0800 <8911180805.AA09410@awesome.berkeley.edu>
  2804. Subject: string(*) vs string(100)
  2805.  
  2806.    Date: Sat, 18 Nov 89 00:05:22 -0800
  2807.    From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2808.  
  2809.    What is the difference between :
  2810.        op ping(from:string(*); to:string(*))
  2811.    and
  2812.        op ping(from:string(100); res to:string(100))
  2813.    ...
  2814.  
  2815. The effect should be the same in your example ...  provided that
  2816. ping's 2nd parameter in the first declaration is made a res parameter
  2817. too; otherwise, it won't get copied back.  (And the name of ping's 2nd
  2818. parameter is changed so it isn't a reserved word.)
  2819.  
  2820. (I'm not sure I completely understood your question.  If not, let me know.)
  2821.  
  2822. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Sat Nov 18 03:10:42 1989
  2823. Received: from ucbvax.Berkeley.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2824.     id AA20136; Sat, 18 Nov 89 03:10:42 MST
  2825. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.39)
  2826.     id AA22727; Sat, 18 Nov 89 02:10:00 -0800
  2827. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  2828.     id AA10157; Sat, 18 Nov 89 02:12:03 PST
  2829. Message-Id: <8911181012.AA10157@awesome.berkeley.edu>
  2830. To: info-sr@arizona.edu
  2831. Subject: possible bug in SR compiler involving ENUM
  2832. Date: Sat, 18 Nov 89 02:12:01 -0800
  2833. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2834.  
  2835.  
  2836. Included below is "bug.sr".  It is trimmed down from a much larger
  2837. application I was working on, and so makes little sense on its own.
  2838. On our setup, this causes a segmentation fault when you try:
  2839. % sr -c bug.sr
  2840.  
  2841. A little poking in the compiler seems to suggest that it is
  2842. processing the line:
  2843.     send o_cap.hello(mycap,x)
  2844.  
  2845. At this point, is checking (I think) that "mycap" which is "cap a" is
  2846. compatible with "cap a_stub" by checking their structural equivalence.
  2847.  
  2848. It tries to see if the two "e_type"s of "a" and "a_stub" are the same
  2849. and ends up charging off the list, since it expects it to be NULL terminated,
  2850. but it is not.  It does not check the "s_size", which seems to record
  2851. the number of enumeration literals in the type.  The s_size *does* seem
  2852. to be consulted in decl.c.
  2853.  
  2854. The relevant code is in sr/sr/sigcmp.c, around lines 70-80
  2855.  
  2856.  
  2857. ----------------- bug.sr ----------------
  2858.  
  2859. resource a_stub
  2860.    type e_type = enum (alpha, beta, gamma)
  2861.    op function()
  2862. end a_stub
  2863.  
  2864.  
  2865. resource other
  2866.    import a_stub
  2867.  
  2868.    op hello(a_cap:cap a_stub; x:e_type)
  2869. body other()
  2870.  
  2871.    process listener
  2872.       var a_cap    :cap a_stub
  2873.       var y:e_type
  2874.       receive hello(a_cap,y)
  2875.    end listener
  2876.  
  2877. end other
  2878.  
  2879.  
  2880. resource a
  2881.    type e_type = enum (alpha, beta, gamma)
  2882.    op function()
  2883.  
  2884.    import other
  2885. body a(o_cap:cap other)
  2886.    var mycap    :cap a
  2887.  
  2888.    initial
  2889.       mycap:=myresource()
  2890.    end initial
  2891.  
  2892.    proc function()
  2893.    end function
  2894.  
  2895.    process server
  2896.       var x:e_type
  2897.       x:=beta
  2898.       send o_cap.hello(mycap,x)
  2899.    end server
  2900. end a
  2901.  
  2902.  
  2903. resource main
  2904. body main()
  2905. end main
  2906.  
  2907. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Sat Nov 18 05:03:05 1989
  2908. Received: from ucbvax.Berkeley.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2909.     id AA25581; Sat, 18 Nov 89 05:03:05 MST
  2910. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.39)
  2911.     id AA28473; Sat, 18 Nov 89 04:02:24 -0800
  2912. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  2913.     id AA11281; Sat, 18 Nov 89 04:04:28 PST
  2914. Message-Id: <8911181204.AA11281@awesome.berkeley.edu>
  2915. To: info-sr@arizona.edu
  2916. Subject: probable SR runtime bug, memory not freed
  2917. Date: Sat, 18 Nov 89 04:04:22 -0800
  2918. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2919.  
  2920.  
  2921. For certain SR programs, I have noticed their SIZE continually increases
  2922. during runtime and if left long enough, there is a "[vm N] out of memory" error.
  2923. Perhaps buffers (for send/receive to remote machines?) are being
  2924. allocated, but never freed.
  2925.  
  2926. Has anyone else noticed this?
  2927.  
  2928. Dave
  2929. djones@awesome.berkeley.edu
  2930.  
  2931. From djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU  Mon Nov 20 02:25:42 1989
  2932. Received: from ucbvax.Berkeley.EDU by megaron.arizona.edu (5.59-1.7/15) via SMTP
  2933.     id AA07942; Mon, 20 Nov 89 02:25:42 MST
  2934. Received: from awesome.Berkeley.EDU by ucbvax.Berkeley.EDU (5.61/1.39)
  2935.     id AA15573; Mon, 20 Nov 89 01:24:57 -0800
  2936. Received: from localhost by awesome.berkeley.edu (4.0/SMI-4.0)
  2937.     id AA16511; Mon, 20 Nov 89 01:27:05 PST
  2938. Message-Id: <8911200927.AA16511@awesome.berkeley.edu>
  2939. To: info-sr@arizona.edu
  2940. Subject: re: memory allocation bug at run time?
  2941. Date: Mon, 20 Nov 89 01:27:02 -0800
  2942. From: djones%awesome.Berkeley.EDU@ucbvax.Berkeley.EDU
  2943.  
  2944. The following example is a simple case of two processes (on different machines)
  2945. sending messages to each other.  Using "ps", or "top", one can watch the
  2946. process size slowly, but continuously, rising ... until we get an
  2947. "out of memeory" error.
  2948.  
  2949. I tried to check alloc's and free's (with setenv SRXDEBUG FFFFF), but
  2950. I didn't learn anything.
  2951.  
  2952. awesome% srm
  2953. awesome% make
  2954. awesome% a.out totally 
  2955.  
  2956. ----------------- membug.sr ------------------------
  2957.  
  2958. /* Memory allocation bug exerciser */
  2959.  
  2960. resource main_stub
  2961.    op done()
  2962. end main_stub
  2963.  
  2964. resource ab
  2965.    op ab_work()
  2966.    import main_stub
  2967. body ab(m:cap main_stub)
  2968.    process ab_server
  2969.       do (true) ->
  2970.          receive ab_work()
  2971.      send m.done()
  2972.       od
  2973.    end ab_server
  2974. end ab
  2975.  
  2976.  
  2977. resource main
  2978.    op done()
  2979.    import ab
  2980. body main()
  2981.    var  n            :int
  2982.  
  2983.    initial
  2984.       n:=numargs()
  2985.       if (n != 1) ->
  2986.      write("give exatcly one host name")
  2987.      flush(stdout)
  2988.      stop
  2989.       fi
  2990.    end
  2991.  
  2992.    process make
  2993.       var s            :string(100)
  2994.       var ab_cap        :cap ab
  2995.       var remote        :cap vm
  2996.  
  2997.       getarg(1,s)
  2998.       locate(1,s)
  2999.       remote:=create vm() on 1
  3000.       ab_cap:=create ab(myresource()) on remote
  3001.       do (true) ->
  3002.          send ab_cap.ab_work()
  3003.      receive done()
  3004.       od
  3005.    end make
  3006. end main
  3007.  
  3008.  
  3009. From gmt  Mon Nov 20 11:02:36 1989
  3010. Date: Mon, 20 Nov 89 11:02:36 MST
  3011. From: "Gregg Townsend" <gmt>
  3012. Message-Id: <8911201802.AA08638@megaron.arizona.edu>
  3013. Received: by megaron.arizona.edu (5.59-1.7/15)
  3014.     id AA08638; Mon, 20 Nov 89 11:02:36 MST
  3015. To: djones@awesome.berkeley.edu
  3016. Subject: bug reports
  3017. Cc: info-sr
  3018.  
  3019. Thank you for the bug reports.
  3020.  
  3021. We're aware of several problems in both of those areas: signature checking
  3022. in the compiler and memory allocation at runtime.  We hope to fix those
  3023. in the next version of the SR system, and will retain your test programs
  3024. to help verify this.
  3025.  
  3026. In general, bug reports should be addressed to sr-project@cs.arizona.edu,
  3027. unless there's a reason for the whole info-sr list to see them.
  3028.  
  3029.     Gregg Townsend / Computer Science Dept / Univ of Arizona / Tucson, AZ 85721
  3030.     +1 602 621 4325     gmt@cs.arizona.edu     110 57 16 W / 32 13 45 N / +758m
  3031.  
  3032.  
  3033.